ホームページ  >  記事  >  ウェブフロントエンド  >  JavaScript では、onscroll イベントの目的は何ですか?

JavaScript では、onscroll イベントの目的は何ですか?

PHPz
PHPz転載
2023-08-29 14:09:021264ブラウズ

JavaScript では、onscroll イベントの目的は何ですか?

要素のスクロール バーがスクロールされると、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 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。