<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素自动滚动到可视范围内</title>
    <style type="text/css">
        .test{height: 5000px;background: #666;}
        .intoview{height: 100px;background: green;}
    </style>
</head>
<body>
    <div ></div>
    <div >1</div>
    <div ></div>

    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
    <script type="text/javascript">
        $(function() {
            setTimeout(function() {
                //$("#m-intoview")[0].scrollIntoView(false);
                $("#m-intoview")[0].scrollIntoViewIfNeeded({behavior: "instant", block: "center", inline: "nearest"});
            }, 2000);
        });
    </script>
</body>
</html>

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-10-06
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
相关资源
相似解决方案