zoukankan      html  css  js  c++  java
  • 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";
  • 相关阅读:
    ASP中使用事务控制
    C语言学习笔记——两个数交换位置的多种方式
    PHP字符串函数
    PHP笔记——文件处理
    算法——穿越沙漠算法
    C学习笔记——使用CL编译器
    Wordpress——一些内部参数记录
    C语言笔记——原码、反码、补码
    C学习笔记——内存
    Linux VI编辑器命令集合
  • 原文地址:https://www.cnblogs.com/200325074/p/1729032.html
Copyright © 2011-2022 走看看