javascript 獲取頁面的高度及滾動條的位置的代碼
更新時間:2010年05月06日 21:14:38 作者:
javascript獲取頁面的高度及滾動條的位置的代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
var Viewport={
top : function(){
return window.pageYOffset
|| document.documentElement && document.documentElement.scrollTop
|| document.body.scrollTop;
},
height : function(){
return window.innerHeight
|| document.documentElement && document.documentElement.clientHeight
|| document.body.clientHeight;
},
left : function(){
return window.pageXOffset
|| document.documentElement && document.documentElement.scrollLeft
|| document.body.scrollLeft;
},
width : function(){
return window.innerWidth
|| document.documentElement && document.documentElement.clientWidth
|| document.body.clientWidth;
},
right : function(){
return Viewport.left() + Viewport.width();
},
bottom : function(){
return Viewport.top() + Viewport.height();
}
};
居中:
復(fù)制代碼 代碼如下:
style.position="absolute";
style.left=50%;
style.top=Viewport.Top()+Viewport.Height()/2+"px";
相關(guān)文章
如何解決attachEvent函數(shù)時,this指向被綁定的元素的問題?
如何解決attachEvent函數(shù)時,this指向被綁定的元素的問題?...2007-04-04幫你徹底搞懂JS中的prototype、__proto__與constructor(圖解)
這篇文章主要介紹了詳解幫你徹底搞懂JS中的prototype、__proto__與constructor(圖解),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08JS實現(xiàn)的tab切換并顯示相應(yīng)內(nèi)容模塊功能示例
這篇文章主要介紹了JS實現(xiàn)的tab切換并顯示相應(yīng)內(nèi)容模塊功能,結(jié)合實例形式分析了JavaScript基于事件響應(yīng)、元素遍歷實現(xiàn)頁面tab切換功能相關(guān)操作技巧,需要的朋友可以參考下2019-08-08