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>