Javascript examples for jQuery Method and Property:scroll
trigger the scroll event for the selected elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> x = 0;//from w w w . ja v a 2 s.c o m $(document).ready(function(){ $("div").scroll(function(){ $("span").text( x+= 1); }); $("button").click(function(){ $("div").scroll(); }); }); </script> </head> <body> <p>Try the scrollbar in the div</p> <div style="border:1px solid black;width:200px;height:100px;overflow:scroll;"> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <br><br> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <br><br> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <br><br> </div> <p>Scrolled <span>0</span> times.</p> <button>Trigger scroll event for the window</button> </body> </html>