Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Javascript

การใช้เหตุการณ์ onscroll ใน JavaScript คืออะไร?


เหตุการณ์ onscroll เกิดขึ้นเมื่อเลื่อนแถบเลื่อนสำหรับองค์ประกอบ คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีใช้งาน onscroll เหตุการณ์ใน JavaScript

ตัวอย่าง

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            border: 2px solid blue;
            width: 300px;
            height: 100px;
            overflow: scroll;
         }
      </style>
   </head>
   
   <body>
      <div id="content">
         This is demo text. This is demo text.This is demo text.This is demo text.
         This is demo text.This is demo text.This is demo text.This is demo text.
         This is demo text.This is demo text.This is demo text.
         This is demo text.This is demo text.This is demo text.
         This is demo text.This is demo text.This is demo text.
      </div>
      <p id = "myScroll"> </p>
      <script>
         document.getElementById("content").onscroll = function() {myFunction()};
         function myFunction() {
            document.getElementById("myScroll").innerHTML = "Scroll successfull!.";
         }
      </script>
   </body>
</html>