使用JavaScript动态伪元素CSS
是否可以动态设置伪元素的CSS? 例如:
jQuery动态样式帮助容器
$('#help').css({ "width" : windowWidth - xOffset, "height" : windowHeight - yOffset, "bottom" : -windowHeight, "left" : 200 });
jQuery尝试设置帮助容器的内部边框:
$('#help:before').css({ "width" : windowWidth - xOffset, "height" : windowHeight - yOffset });
上面的CSS文件
#help { opacity: 0.9; filter:alpha(opacity=90); -moz-opacity: 0.9; z-index: 1000000; bottom: -550px; left: 400px; background-color: #808080; border: 5px dashed #494949; -webkit-border-radius: 20px 20px 20px 20px; -moz-border-radius: 20px 20px 20px 20px; border-radius: 20px 20px 20px 20px; } #help:before { border: 5px solid white; content: ''; position: absolute; -webkit-border-radius: 20px 20px 20px 20px; -moz-border-radius: 20px 20px 20px 20px; border-radius: 20px 20px 20px 20px; }
你不能直接通过jQuery来做。
看看这个问题: 从JavaScript设置CSS伪类规则
@ Box9的答案可能就是你应该使用的答案 :
为此,我把一个小型库聚集在一起,因为我认为在JS中有一些有效的用例来操作样式表。
不要使用.css()
设置宽度和高度,而应直接使用.width()
和height()
。