第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

對(duì)js中的各種寬高理解

標(biāo)簽:
JavaScript
<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>各种宽高的理解</title>
        <style type="text/css">
            * {
                padding: 0;
                margin: 0
            }

            #test {
                width: 100px;
                height: 100px;
                padding: 10px;
                margin: 10px;
                border: 1px solid blue;
                overflow: auto;
            }
        </style>
    </head>

    <body>
        <div id="test">
            <div style="height: 200px;"></div>
        </div>
        <script type="text/javascript">
            //以下说明只在谷歌浏览器有效,其他浏览器略有差别
            var test = document.getElementById("test");
            console.log(test.clientHeight + '-' + test.clientWidth); //120---103
            console.log(test.clientLeft + '-' + test.clientTop); //1---1
            //clientHeight,clientWidth指的是元素可视部分的宽高,即等于padding+content;
            //如果有滚条,需要减去滚动条的宽高。
            //clientLeft,clientTop返回的是元素周围边框的厚度。
            console.log("-------------------------");
            console.log(test.offsetHeight + '-' + test.offsetWidth); //122---122
            console.log(test.offsetLeft + '-' + test.offsetTop); //10---10
            console.log(test.offsetParent);
            //offsetHeight,offsetWidth. 等于padding+content+border;
            //offsetLeft,offsetTop为相对于offsetParent的偏移量
            //他们与是否有滚动条无关
            console.log("-------------------------");
            console.log(test.scrollHeight + '-' + test.scrollWidth); //220---103
            console.log(test.scrollLeft + '-' + test.scrollTop); //0---0
            //scrollHeight,scrollWidth指的是元素实际的宽高,即等于padding+content;
            //如果有滚条,需要减去滚动条的宽高。
            //scrollLeft,scrollTop指的是元素被卷起的宽高,可读可写
            test.onclick = function(event) {
                    var e = event || window.event;
                    console.log("event的五种坐标----");
                    console.log(event.clientX + 'client坐标' + event.clientY);
                    console.log(event.offsetX + 'offset坐标' + event.offsetY);
                    console.log(event.pageX + 'page坐标' + event.pageY);
                    console.log(event.screenX + 'screen坐标' + event.screenY);
                    console.log(event.x + '坐标' + event.y);
                }
                //event.clientX,event.clientY---相对于浏览器可视区左上角的坐标
                //event.offsetX,event.offsetY---相对于事件源左上角的坐标
                //event.pageX,event.pageY---相对于整个网页左上角的坐标
                //event.screenX,event.screenY---相对于设备屏幕左上角的坐标
                //event.x,event.y---与client坐标相同
            console.log(window.innerHeight + '-' + window.innerWidth);
            //窗口的宽高,不包括菜单栏
            console.log(window.outerHeight + '-' + window.outerWidth);
            //整个窗口的宽高,包括窗口的一切
            console.log(window.screenLeft + '-' + window.screenTop);
            //窗口距离屏幕左边和上边的距离
            console.log(window.screen.availWidth + '-' + window.screen.availHeight);
            //屏幕的宽高
            console.log(window.screen.availLeft + '-' + window.screen.availTop); //为0
        </script>
    </body>

</html>
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消