javascript 獲取頁面的高度及滾動條的位置的代碼
更新時間:2010年05月06日 21:14:38 作者:
javascript獲取頁面的高度及滾動條的位置的代碼,需要的朋友可以參考下。
復制代碼 代碼如下:
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();
}
};
居中:
復制代碼 代碼如下:
style.position="absolute";
style.left=50%;
style.top=Viewport.Top()+Viewport.Height()/2+"px";
相關(guān)文章
Javascript中數(shù)組sort和reverse用法分析
這篇文章主要介紹了Javascript中數(shù)組sort和reverse用法,實例分析了sort和reverse使用時的注意事項與相關(guān)技巧,具有不錯的參考借鑒價值,需要的朋友可以參考下2014-12-12
Bootstrap分頁插件之Bootstrap Paginator實例詳解
Bootstrap Paginator是一款基于Bootstrap的js分頁插件,功能很豐富,個人覺得這款插件已經(jīng)無可挑剔了,感興趣的朋友跟著腳本之家小編一起學習吧2016-10-10
使用UrlConnection實現(xiàn)后臺模擬http請求的簡單實例
這篇文章主要介紹了使用UrlConnection實現(xiàn)后臺模擬http請求的簡單實例的相關(guān)資料,需要的朋友可以參考下2017-01-01
bootstrap datepicker限定可選時間范圍實現(xiàn)方法
這篇文章主要介紹了bootstrap datepicker限定可選時間范圍的實現(xiàn)方法,本文涉及到相關(guān)知識點,通過實例給大家介紹的非常詳細,需要的朋友可以參考下2016-09-09

