Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript/jQuery를 사용하여 페이지 상단으로 스크롤하는 방법은 무엇입니까?

<시간/>

예시

라이브 데모

<html>
   <body>
      <script>
         $("a").click(function() {
            $("html, body").animate({ scrollTop: 0 }, "slow");
            return false;
         });
      </script>
      <h3>TOP OF PAGE</h3>
      <br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.
      <br>
      <h3>BOTTOM OF PAGE</h3>
      <a href="#">Scroll up</a>
   </body>
</html>