给伪元素的css属性动态赋值以及获取css属性值
一/ 设置值
就是动态添加style
$('head').append($('<style class="styleBefore">.leveltwo-scroll::before{height:' + domRight + 'px;}</style>'));
二/ 获取值
#leveltwo-scroll::before {
content: 'hai';
position: absolute;
top: 0;
left: 7px;
width: 0.5px;
height: 0px;
background-color: #ccc;
}
//获取值
var myIdElement = document.getElementById("leveltwo-scroll");
var beforeStyle = window.getComputedStyle(myIdElement, ":before");
console.log(beforeStyle); // [CSSStyleDeclaration Object]
console.log(beforeStyle.width); // 0.5px
console.log(beforeStyle.getPropertyValue("width")); // 0.5px
console.log(beforeStyle.content); // "hai"
参考文章
还没有评论,来说两句吧...