***獲取螢幕寬高 :width(),height(),clientHeight,clientWidth 獲取寬高的區別*
獲取螢幕寬高 :width(),height(),clientHeight,clientWidth 獲取寬高的區別
$(window).width() & $(window).height():獲得的是螢幕可視區域的寬高,不包括滾動條與工具條。
$(window).height() = height+padding
$(window).width() = width+padding
document.documentElement.clientWidth & docuemnt.documentElement.clientHeight 同樣是獲取可視區域的寬高,不包括滾動條和工具欄。等同於jqde (window).height
window.innerHeight & window.innerWidth 獲取到可視區域的寬高,並加上了滾動條的寬高。
window.outerWidth & window.outerHeight:獲得到可視區域的寬高 並且加上工具條與滾動條視窗的寬度與高度。
offsetLeft & offsetTop
所有HTML元素擁有offsetLeft和offsetTop屬性來返回元素相對於父級元素的X和Y座標
scrollLeft & scrollTop
指定的是元素的滾動條的位置,可以通過設定scrollLeft & scrollTop的值來改變元素滾動條的位置
相容性
1.window innerWidth 和 innerHeight 屬性與outerWidth和outerHeight屬性IE8以及以下不支援。
2.測試瀏覽器IE,火狐,谷歌,360瀏覽器,Safari都支援document.documentElement.clientWidth與document.documentElement.clientHeight。