字母表的製做 parent.scrollTo()

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .fa {
      height: 400px;
      background: yellow;
      position: relative;
      overflow-y: scroll;
    }

    .son {
      height: 300px;
      margin-bottom: 10px;
      background-color: turquoise;
    }
  </style>
</head>

<body>
  <div class="fa" id="fa">
    <div class="son">1</div>
    <div class="son">2</div>
    <div class="son" id="test">3</div>
    <div class="son">4</div>
  </div>
  <script>
    console.log(test.offsetParent);
    console.log(test.offsetTop);
    test.offsetParent.scrollTo(0, test.offsetTop)
  </script>
</body>

</html>
相關文章
相關標籤/搜索