zoukankan      html  css  js  c++  java
  • scrollTop和scrollLeft属性

    外层元素的高度值是200px,内层元素的高度值是300px。很明显,“外层元素中的内容”高过了“外层元素”本身.当向下拖动滚动条时,有部分内容会隐没在“外层元素的上边界”之外,scrollTop就等于这部分“不可见的内容”的高度。 

    scrollLeft也是这样。

    <html>
        <head>
            <title>test scrollTop</title>
            <style type="text/css">
                #out{
                    width:300px;
                    height:200px;
                    background-color:yellow;
                    overflow:auto;
                }
                #in{
                    width:400;
                    height:300;
                    background-color:red;
                    overflow:auto;
                }
            </style>
            <script type="text/javascript">
                function scollT(){
                    var scrollTopSize = document.getElementById("out").scrollTop;
                    var scrollLeftSize = document.getElementById("out").scrollLeft;
                    console.log("scrollTop:" + scrollTopSize + ",scrollLeft:" + scrollLeftSize);
                }
            </script>
        </head>
        <body>
            <div id="out" onscroll="scollT()">
                <div id="in">
                    <table>
                        <tr>
                            <th>姓名</th>
                            <th>年龄</th>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                        <tr>
                            <td>1<td>
                            <td>2</td>
                        </tr>
                            
                    </table>
                </div>
            </div>
        </body>
        
    </html>
  • 相关阅读:
    maria-developers 开发者邮件
    Parallel Programming--perfbook
    面向对象设计模式中类与类关系
    binlog 轻松的找到没有及时提交的事物(infobin工具
    deeplearningbook-chinese
    Introduction to the Optimizer --cbo
    dell T420热插拔安装过程
    MySQL是如何利用索引的
    BTrace housemd TProfiler
    杨建荣的学习笔记
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/6872370.html
Copyright © 2011-2022 走看看