zoukankan      html  css  js  c++  java
  • js 盒子模型及方法


    clientWidth  =内容+padding
    offsetWidth  =内容+padding+border

    //获得左 上偏移量 利用offsetParent

    function getElementLeft(ele){
        var actualLeft=ele.offsetLeft;
        var current=ele.offsetParent;
        while(current!==null){
            actualLeft+=current.offsetLeft;    
            current=current.offsetParent;
        }
        return actualLeft;
    }

    function getElementTop(ele){
        var actualTop=ele.offsetTop;
        var current=ele.offsetParent;
        while(current!==null){
            actualTop+=current.offsetTop;
            current=current.offsetParent;
        }
        return actualTop;
    }

    //可视区宽度
    function getViewport(){
        if(document.compatMode=="BackCompat"){//标准模式关闭 BackCompat混杂模式
            return {
                document.body.clientWidth;
                height:document.body.clientHeight;
            }
        
        }else{//标准模式开启  CSS1Compat
        
            return {
                document.documentElement.clientWidth;
                height:document.documentElement.clientHeight;
            }
        }
    }

  • 相关阅读:
    软件测试常见概念
    Apollo简介及工作原理
    bug的编写技巧与级别划分
    native与H5优缺点及H5测试
    优惠券测试
    go语言-for循环
    go语言-流程控制--if
    go语言-二进制与位运算
    cookie和session
    AJAX
  • 原文地址:https://www.cnblogs.com/xiaomier/p/2943049.html
Copyright © 2011-2022 走看看