Javascript
 Computer >> コンピューター >  >> プログラミング >> Javascript

JavaScriptでのonscrollイベントの使用法は何ですか?


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>

  1. JavaScriptでのscreenYマウスイベントの役割は何ですか?

    イベントがトリガーされると、 screenY mouseイベントは、マウスポインタの垂直座標を返します。 例 次のコードを実行して、 screenYを実装する方法を学ぶことができます。 JavaScriptでのマウスイベント。 <!DOCTYPE html> <html>    <body>       <p onclick = "coordsFunc(event)">Click here to get the x (horizontal) and y (vertical)

  2. JavaScriptでのevery()メソッドの使用法は何ですか?

    JavaScript配列すべて メソッドは、配列内のすべての要素が、提供された関数によって実装されたテストに合格するかどうかをテストします。 以下はパラメータです- コールバック −各要素をテストする関数。 thisObject −コールバックを実行するときにこれとして使用するオブジェクト。 例 次のコードを実行して、すべての()を操作する方法を学ぶことができます。 JavaScriptのメソッド- <html>    <head>       <title>JavaScript Array eve