jQuery .scroll() event

Syntax and Description


.scroll(handler)            
.scroll()

handler is a function to execute each time the event is triggered. Return value is the jQuery object, for chaining purposes.

scroll method binds an event handler to the scroll JavaScript event, or trigger that event on an element.

.scroll(handler) is a shortcut for .bind('scroll', handler). .scroll() is a shortcut for and .trigger('scroll').

scroll(fn) event fires when a document view is scrolled.

We can trigger the event manually when another element is clicked.


$('#other').click(function() {
/*from  www .  java  2 s .c om*/
 $('#target').scroll();

});

Listen to scroll event


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w w  w .ja  v  a2s  . co  m-->
            $(window).scroll(function () { 
              $("span").css("display", "inline").fadeOut("slow"); 
            });
        });
    </script>
  </head>
  <body>
    <body>
         <span>Scroll happened! java2s.com</span>
    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities