zoukankan      html  css  js  c++  java
  • JS的scrollIntoView

    scrollIntoView(alignWithTop)  滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素。如果alignWithTop为true,或者省略它,窗口会尽可能滚动到自身顶部与元素顶部平齐;如果alignWithTop为false,则元素下边框与视窗底部齐平

    例:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>scrollIntoView</title>
    <style type="text/css">
    body{
    height: 20000px;
    }
    #pink{
    margin: 1000px auto 100px;
    100px;
    height: 200px;
    background-color: pink;
    }
    </style>
    </head>
    <body>
    <button id="btn">点我</button>
    <div id="pink"></div>
    <script type="text/javascript">
    document.getElementById('btn').addEventListener('click', function () {
    document.getElementById('pink').scrollIntoView(true);
    })
    </script>
    </body>
    </html>

  • 相关阅读:
    第九章
    第十章
    第八章
    第七章
    第六章
    第五章
    第四章
    第三章
    第二章
    第一章
  • 原文地址:https://www.cnblogs.com/carriezhao/p/6857408.html
Copyright © 2011-2022 走看看