zoukankan      html  css  js  c++  java
  • 随滚动条滚动的居中div

    <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
    transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"> 遨游、火狐浏览器就用这个吧-->
    <!DOCTYPE>
    <<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题</title>
    </head>
    <body>

    </body>
    </html>
    <head>
        <meta charset="UTF-8">
        <title>随滚动条滚动的居中div</title>
       
        <script type="text/javascript">
        function scrollBox(){
                    document.getElementById("centerBox").style.top=(document.documentElement.scrollTop+
            (document.documentElement.clientHeight-document.getElementById("centerBox").offsetHeight)/2)+"px";
                    document.getElementById("centerBox").style.left=(document.documentElement.scrollLeft+
            (document.documentElement.clientWidth-document.getElementById("centerBox").offsetWidth)/2)+"px";
        }
        window.onload=function(){
            scrollBox();
        }
        window.onscroll=function(){
            scrollBox();
        }

        // function test(){
        //     scrollBox();
        // }
        // window.onscroll=test;//注意别写成onScroll,JS是区分大小写的,我就因为写错了,搞了半天效果都没出来
        // window.onload=test;//注意别写成onLoad
        </script>
    </head>
    <body>
    <div style="400px; height:400px; border:1px solid #f1f1f1; background-color:red; position:absolute;
    top:0px; left:0px;" id="centerBox"></div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div>复制多行</div>
    <div style="1200px;">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
    </body>
    </html>

    PS:QMM亲自动手做的,自己做的总有成就感!

  • 相关阅读:
    根据第三方提供的wsdl报文(axis2开发),进行的webservice应用的开发实例
    调用axis2开发的接口遇到的问题
    使用 DJ Java Decompiler 将整个jar包反编译成源文件
    解析Myeclipse项目下的.classpath文件
    使用cxf开发webservice应用时抛出异常
    hibernate 映射 多对一
    jquery获取元素的值,获取当前对象的父对象等等
    web项目中加入struts2、spring的支持,并整合两者
    Struts2中的 配置文件
    对list集合中的对象按照对象的某一属性进行排序
  • 原文地址:https://www.cnblogs.com/QMM2008/p/4131142.html
Copyright © 2011-2022 走看看