HTML | onscroll Attribute

This onscroll attribute works when an element scrollbar is being scrolled. To create a scrollbar in an element, use the CSS overflow property.

Syntax:

<element onscroll = "script">

Attribute: This attribute is supported by all HTML elements and the attribute works when script triggered.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>onscroll attribute</title>
        <style>
            #sudo {
                border: 1px solid black;
                width: 200px;
                height: 100px;
                overflow: scroll;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
        <body>
            <center>
            <h1>GeeksforGeeks</h1>
            <h2>onscroll attribute</h2>
              
            <div id="sudo" onscroll="Geeks()">GeeksforGeeks: A computer
            science portal for geeks.It ia a good wqebsite for learning 
            computer science. It has a good programming Question and 
            have many Interwiew Experiences. Prepare for the Recruitment
            drive of product based companies like Microsoft, Amazon, 
            Adobe etc with a free online placement preparation course. 
            The course focuses on various MCQ's & Coding question likely
            to be asked in the interviews & make your upcoming placement
            season efficient and successful. 
            </div>
            <script>
                function Geeks() {
                    document.getElementById("sudo").style.color = "green";
                }
            </script>
            </center>
    </body>
</html>                            

chevron_right


Output:

Supported Browsers: The browser supported by onscroll attribute are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.