• 随滚动条滚动的居中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亲自动手做的,自己做的总有成就感!

  • 相关阅读:
    端口号被占用怎么办
    cxgrid动态显示行号
    SQL事件探查器后无法暂停及停止
    互联网电视音视频编码规范
    视频服务之ffmpeg部署
    如何远程连接AWSEC2实例
    测试kernel.pid_max值
    ffmpeg常用命令
    视频服务之(直播&点播)
    视频服务之在线教育系统BigBlueButton
  • 原文地址:https://www.cnblogs.com/QMM2008/p/4131142.html
Copyright © 2020-2023  润新知