jQuery中的height innerHeight outerHeight區(qū)別示例介紹
更新時(shí)間:2014年06月15日 17:24:36 投稿:whsnow
這篇文章主要介紹了jQuery中的height innerHeight outerHeight的區(qū)別,需要的朋友可以參考下
標(biāo)準(zhǔn)瀏覽器下:
height:高度
innerHeight:高度+補(bǔ)白
outerHeight:高度+補(bǔ)白+邊框,參數(shù)為true時(shí):高度+補(bǔ)白+邊框+邊距
html代碼:
<div class="width: 150px;height:20px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:17px,37px,41px,61px
在ff中的結(jié)果:20px,40px,44px,64px
html代碼:
<div class="width: 150px;height: 41px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
[html]
結(jié)果:
在ie中的結(jié)果:17px,37px,41px,61px
在ff中的結(jié)果:41px,61px,65px,85px
html代碼:
[code]
<div class="width: 150px;height: 42px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:18px,38px,42px,62px
在ff中的結(jié)果:42px,62px,66px,86px
html代碼:
<div class="width: 150px;height: 60px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:36px,56px,60px,80px
在ff中的結(jié)果:60px,80px,84px,104px
結(jié)論:在ie中height包含border和padding并且height最小值為17px ,同理可得width,不過(guò)它最小值為15px
height:高度
innerHeight:高度+補(bǔ)白
outerHeight:高度+補(bǔ)白+邊框,參數(shù)為true時(shí):高度+補(bǔ)白+邊框+邊距
html代碼:
復(fù)制代碼 代碼如下:
<div class="width: 150px;height:20px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
復(fù)制代碼 代碼如下:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:17px,37px,41px,61px
在ff中的結(jié)果:20px,40px,44px,64px
html代碼:
復(fù)制代碼 代碼如下:
<div class="width: 150px;height: 41px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
復(fù)制代碼 代碼如下:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
[html]
結(jié)果:
在ie中的結(jié)果:17px,37px,41px,61px
在ff中的結(jié)果:41px,61px,65px,85px
html代碼:
[code]
<div class="width: 150px;height: 42px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
復(fù)制代碼 代碼如下:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:18px,38px,42px,62px
在ff中的結(jié)果:42px,62px,66px,86px
html代碼:
復(fù)制代碼 代碼如下:
<div class="width: 150px;height: 60px;float: left;border: 2px solid red;margin: 10px;margin: 10px;padding: 10px;" id="test">jjjjj</div>
js代碼:
復(fù)制代碼 代碼如下:
alert($("#test").height());
alert($("#test").innerHeight());
alert($("#test").outerHeight());
alert($("#test").outerHeight(true));
結(jié)果:
在ie中的結(jié)果:36px,56px,60px,80px
在ff中的結(jié)果:60px,80px,84px,104px
結(jié)論:在ie中height包含border和padding并且height最小值為17px ,同理可得width,不過(guò)它最小值為15px
相關(guān)文章
jQuery實(shí)現(xiàn)表格展開(kāi)與折疊的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)表格展開(kāi)與折疊的方法,涉及jQuery中toggleClass方法與鏈?zhǔn)讲僮鞯南嚓P(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-05-05
jquery實(shí)現(xiàn)手風(fēng)琴效果實(shí)例代碼
這篇文章介紹了jquery實(shí)現(xiàn)手風(fēng)琴效果實(shí)例代碼,有需要的朋友可以參考一下2013-11-11
jQuery1.9.1針對(duì)checkbox的調(diào)整方法(prop)
這篇文章主要介紹了jQuery1.9.1針對(duì)checkbox的調(diào)整方法,用prop代替attr2014-05-05
自寫(xiě)的jQuery異步加載數(shù)據(jù)添加事件
這篇文章主要介紹一個(gè)自寫(xiě)的jQuery異步加載數(shù)據(jù)添加事件的方法,需要的朋友可以參考下2014-05-05
jQuery+CSS 半開(kāi)折疊效果原理及代碼(自寫(xiě))
jQuery做一個(gè)可以半折疊的DIV元素由于jQueryUI中accordion沒(méi)有提供相關(guān)的方法因此自己寫(xiě)了個(gè),代碼質(zhì)量很低希望大家多多指點(diǎn)2013-03-03
用jQuery實(shí)現(xiàn)優(yōu)酷首頁(yè)輪播圖
本文主要介紹了用jQuery實(shí)現(xiàn)優(yōu)酷首頁(yè)輪播圖的思路與方法。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
jquery實(shí)現(xiàn)定時(shí)自動(dòng)輪播特效
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)定時(shí)自動(dòng)輪播特效,講解內(nèi)容很詳細(xì),條理清晰,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-12-12

