源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

javascript 获取页面的高度及滚动条的位置的代码

  • 时间:2022-08-09 06:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript 获取页面的高度及滚动条的位置的代码
[u]复制代码[/u] 代码如下:
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(); } };
居中:
[u]复制代码[/u] 代码如下:
style.position="absolute"; style.left=50%; style.top=Viewport.Top()+Viewport.Height()/2+"px";
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部