滚动事件

作者: 椋椋夜色 | 来源:发表于2019-05-15 22:12 被阅读0次

    <!DOCTYPE html>
    <html lang="zh-CN">

    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> 滚动事件 </title>

        <!--  滚动事件:onscroll: 在滚动时触发; -->
    
        <style>
            .box {
                width: 200px;
                height: 200px;
                background-color: #f00;
                overflow: auto;
            }
    
            img {
                vertical-align: top;
            }
        </style>
    
    </head>
    
    <body>
    
        <div class="box">
            <img src="../images/01.jpg" alt="">
        </div>
    
        <script>
            // 添加滚动事件
            document.querySelector('.box').onscroll = function () {
                // 将滚动值打印在控制台;
                console.log(this.scrollLeft, this.scrollTop);
            }
        </script>
    

    </body>

    </html>

    相关文章

      网友评论

        本文标题:滚动事件

        本文链接:https://www.haomeiwen.com/subject/qtlvaqtx.html