當元素的捲軸被捲動時,會觸發onscroll事件。您可以嘗試執行以下程式碼來了解如何在JavaScript中實作onscroll 事件。
<!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>#
以上是在JavaScript中,onscroll事件的用途是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!