首页 > Web开发 > 详细

获取元素计算后的css样式封装

时间:2016-12-24 19:40:41      阅读:158      评论:0      收藏:0      [点我收藏+]

获取元素计算后的css样式封装:

    function getCss(obj,attribute) {
        if(obj.currentStyle) {
            return obj.currentStyle[attribute];}else {
        return window.getComputedStyle(obj,null)[attribute];}
    }

案例:

<!DOCTYLE html>
<html>
<head>
    <meta charset="uft-8" />
    <style>
        #box {width:100px; height: 100px; background:#dfd; position:absolute; left:100px; top:100px;}
    </style>
</head>
<body>
<button id="btn1">200</button>
<button id="btn2">600</button>
<div id="box"></div>
</body>
</html>
<script>
    function getCss(obj,attribute) {
        if(obj.currentStyle) {
            return obj.currentStyle[attribute];}else {
        return window.getComputedStyle(obj,null)[attribute];}
    }
    console.log(getCss(box,‘zIndex‘));
</script>

 

获取元素计算后的css样式封装

原文:http://www.cnblogs.com/darkterror/p/6217992.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!