美文网首页
JS如何设置盒模型的宽和高

JS如何设置盒模型的宽和高

作者: 成熟稳重的李先生 | 来源:发表于2021-04-15 21:13 被阅读0次
    //只能获取内联样式设置的宽高
    dom.style.width/height
    
    //获取渲染后即时运行的宽高,值是准确的。但只支持 IE
    dom.currentStyle.width/height
    
    //获取渲染后即时运行的宽高,值是准确的。兼容性更好
    window.getComputedStyle(dom).width/height;
    
    //获取渲染后即时运行的宽高,值是准确的。兼容性也很好,一般用来获取元素的绝对位置,getBoundingClientRect()会得到4个值:left, top, width, height
    dom.getBoundingClientRect().width/height;
    

    相关文章

      网友评论

          本文标题:JS如何设置盒模型的宽和高

          本文链接:https://www.haomeiwen.com/subject/iagphktx.html