码迷,mamicode.com
首页 > Web开发 > 详细

js修改伪类元素样式

时间:2017-01-03 15:18:34      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:for   top   元素   getc   etc   div   val   put   styles   

<style type="text/css">
.htmlbox_close::before,
.htmlbox_close::after {
content: ‘‘;
position: absolute;
height: 2px;
top: 4%;
width: 3%;
left: 2%;
margin-top: -1px;
background: #51aed9;
height: 1.1%;
}

.htmlbox_close::before {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}

.htmlbox_close::after {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
</style>
</head>

<body>
<div class="htmlbox_close"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var str = window.getComputedStyle($(‘.htmlbox_close‘)[0], ‘::before‘).getPropertyValue(‘top‘);
console.log(str);
document.styleSheets[0].addRule(‘.htmlbox_close::before‘, ‘top:100px‘);
document.styleSheets[0].insertRule(‘.htmlbox_close::before { top:100px }‘, 0);
document.styleSheets[0].addRule(‘.htmlbox_close::after‘, ‘top:100px‘);
document.styleSheets[0].insertRule(‘.htmlbox_close::before { top:100px }‘, 0);

var str2 = window.getComputedStyle($(‘.htmlbox_close‘)[0], ‘::before‘).getPropertyValue(‘top‘);
console.log(str2);
</script>
</body>

js修改伪类元素样式

标签:for   top   元素   getc   etc   div   val   put   styles   

原文地址:http://www.cnblogs.com/miraclesakura/p/6244612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!