zoukankan      html  css  js  c++  java
  • 获取元素计算后的css样式封装

    获取元素计算后的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 {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>
  • 相关阅读:
    枚举类型的应用
    动手动脑
    四则运算和验证码--源码
    ATM源码
    javabean+jsp+servlet+jdbc
    四则运算改良
    Java异常
    课后总结
    包装类Integre
    对象验证
  • 原文地址:https://www.cnblogs.com/darkterror/p/6217992.html
Copyright © 2011-2022 走看看