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>

  • 相关阅读:
    HTML框架
    HTML链接
    kzalloc 函数详解(转载)
    LCD接口(转载)
    S3C2440上RTC时钟驱动开发实例讲解(转载)
    PHP 真值与空值
    http chunked 理解
    c# 基础
    美式音标注意事项
    groovy 闭包
  • 原文地址:https://www.cnblogs.com/carriezhao/p/6857408.html
Copyright © 2011-2022 走看看