ドキュメント

Events/scroll

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

scroll( fn )

Bind a function to the scroll event of each matched element.
The scroll event fires when a document view is scrolled.
Arguments:
fnFunction
A function to bind to the scroll event on each of the matched elements.
function callback(eventObject) {
  this; // dom element
}
Examples:

To do something when your page is scrolled:

    $("p").clone().appendTo(document.body);
    $("p").clone().appendTo(document.body);
    $("p").clone().appendTo(document.body);
    $(window).scroll(function () { 
      $("span").css("display", "inline").fadeOut("slow"); 
    });

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("p").clone().appendTo(document.body);
    $("p").clone().appendTo(document.body);
    $("p").clone().appendTo(document.body);
    $(window).scroll(function () { 
      $("span").css("display", "inline").fadeOut("slow"); 
    });

  });
  </script>
  <style>
  div { color:blue; }
  p { color:green; }
  span { color:red; display:none; }
  </style>
</head>
<body>
  <div>Try scrolling the iframe.</div>
  <p>Paragraph - <span>Scroll happened!</span></p>
</body>
</html>

NameType