Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

jQuery | scroll() with Examples

  • Last Updated : 13 Feb, 2019

The scroll() is an inbuilt method in jQuery which is used to user scroll in the specified element. This method works for all scrollable elements and the browser window.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

$(selector).scroll(function)

Parameter: This method accepts single parameters function which is optional. It is used to specify the function to run when the scroll event is triggered.
Return Value: It binds an event when scroll is happen for the specified element.

Below program illustrates the scroll() method in jQuery:

Example:




<!DOCTYPE html>
<html>
    <head>
        <title>scroll method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("div").scroll(function() {
                    alert("scroll happened");
                });
            });
        </script>
        <style>
            div {
                border: 1px solid black;
                width: 500px;
                height: 100px;
                overflow: scroll;
            }
        </style>
    </head>
    <body>
       
        <!-- scroll inside this div box -->
        <div>Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!
             Welcome to GeeksforGeeks!.
             Welcome to GeeksforGeeks!
        </div>
    </body>
</html>

Output:
After scrolling inside the div box.
scroll method




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!