The Wayback Machine - https://web.archive.org/web/20240920014719/https://www.geeksforgeeks.org/html-dom-onscroll-event/
Open In App

HTML | DOM onscroll Event

Last Updated : 27 Jul, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The HTML DOM onscroll event occurs when a scrollbar is used. CSS overflow is used to create a scrollbar.
Supported tags

  • <address>
  • , <blockquote>
  • , <body>
  • , <caption>
  • , <center>
  • , <dd>
  • , <dir>
  • , <div>
  • , <dl>
  • , <dt>
  • , <fieldset>
  • , <form>
  • , <h1>to <h6>
  • , <html>
  • , <li>
  • , <menu>
  • , <object>
  • , <ol>
  • , <p>
  • , <pre>
  • , <select>
  • , <tbody>
  • , <textarea>
  • , <tfoot>
  • , <thead>
  • , <ul>

Syntax: 
 

  • In HTML: 
     
<element onscroll="myScript">
  • In JavaScript: 
     
object.onscroll = function(){myScript};
  • In JavaScript, using the addEventListener() method: 
     
object.addEventListener("scroll", myScript);
  •  

Example: Using the addEventListener() method 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM onscroll Event
    </title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <h2>HTML DOM onscroll Event</h2>
        <textarea style="width:100%" id="tID">
            HTML stands for Hyper Text Markup Language.
          It is used to design web pages using markup language.
          HTML is the combination of Hypertext and Markup language.
          Hypertext defines the link between the web pages.
          Markup language is used to define the text document
          within tag which defines the structure of web pages.
          HTML is a markup language which is used by the browser
          to manipulate text, images and other content to
          display it in required format.
        </textarea>
 
        <p id="try"></p>
 
    </center>
    <script>
        document.getElementById(
          "tID").addEventListener("scroll", GFGfun);
 
        function GFGfun() {
            document.getElementById(
              "try").innerHTML = "Textarea scrolled.";
        }
    </script>
 
</body>
 
</html>


Output: 
 

Supported Browsers: The browsers supported by HTML DOM onscroll Event are listed below: 
 

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

 



Similar Reads

How to create Infinite Scrolling using onScroll Event in JavaScript?
We have seen many shopping sites that list some limited number of products(using a back-end API) when we open the website and scroll down to the bottom, we see that more products are fetched and displayed, and as we scroll even further even more products are loaded and fetched and it keeps happening till there are no more products to be displayed.
3 min read
React onScroll Event
React onScroll helps to listen for scroll interactions within specific elements and trigger actions accordingly. It triggers whenever the scrolling position changes within the specified element. It is useful when implementing infinite scrolling, parallax effects, lazy loading, or dynamic UI changes. It is similar to the HTML DOM onscroll event but
4 min read
HTML onscroll Attribute
The onscroll attribute works when an element scrollbar is being scrolled. To create a scrollbar in an element, use the CSS overflow property. It is triggered when the content within an HTML element is scrolled and used to implement dynamic behaviors based on the scroll position and employed for creating effects like parallax scrolling or revealing
4 min read
How to rotate a particular string onScroll in ReactJS ?
In, this article, we will see how we can rotate a text while Scrolling to give a nice user experience by using an npm package react-scroll-rotate. Prerequisites:NodeJS or NPMReact JSSyntax: &lt;ScrollRotate&gt; &lt;/ScrollRotate&gt;We wrap the text within these tags which we want to show effects. Steps to Create the React Application And Installing
2 min read
HTML DOM fullscreenerror Event
The HTML DOM fullscreenerror event occurs when an element can not be viewed in full-screen mode, even if it has been requested. Use the element.requestFullscreen() method to view an element in fullscreen mode and the element.exitFullscreen() method to cancel fullscreen mode. Supported Tags It supports all HTML elements. Syntax: In HTML: &lt;element
1 min read
HTML | DOM onvolumechange Event
The onvolumechange event in HTML DOM occurs when the media volume is changed. Use volume property to set/return the volume of the media.This event is invoked by: Volume increasing/decreasingMuting/unmuting the media player Supported Tags &lt;audio&gt;&lt;video&gt; Syntax: In HTML: &lt;element onvolumechange="myScript"&gt;In JavaScript: object.onvol
1 min read
HTML DOM onopen Event
The DOM onopen event occurs on an open connection with an event source. Related events: onmessage: Received the message.onerror: The problem occurs. Syntax: Using JavaScript:object.onopen = function(){myScript};Using the addEventListener() method:object.addEventListener("open", myScript); Example: Using the addEventListener() method C/C++ Code &lt;
1 min read
HTML DOM ondragleave Event
The ondragleave event occurs when a draggable element or text selection leaves a valid drop target. The ondragenter and ondragleave events can help the user to understand dropzone.There are some events that are used and occurred in the different stages of a drag and drop operation: ondragstart: occurs when dragging of an element started.ondrag: occ
3 min read
HTML DOM onpaste Event
The HTML DOM onpaste event occurs when some content is pasted in an element. this event works on every element like in &lt;p&gt; element if contenteditable set is true then we can paste content in &lt;p&gt; element. The HTML DOM onpaste event is mostly used in input element type="text". Supported Tags: It supports all HTML Elements. Syntax: In HTML
1 min read
HTML | DOM touchcancel Event
The touchcancel event is used to execute a script when the touch event gets interrupted. It is considered a good practice to include the touchcancel event to clean up the code if the devices interrupt a touch event at different actions.Supported Tags All HTML elements supported by this event. Supported Tags &lt;details&gt; Syntax: object.ontouchcan
1 min read
HTML | DOM touchmove Event
The touchmove event is used to execute a script when the user moves the finger across the screen. It works only on touch screen devices and triggers once for every movement and continues to trigger until the finger is released.Supported Tags All HTML elements supported by this event. Syntax: object.ontouchmove = myScript; Below program illustrates
1 min read
HTML | DOM Storage Event
The Storage Event in HTML DOM is used to make change in the storage area in the context of another document. When there is modification in the storage area of the window, a storage event is sent to that window. Syntax: window.addEventListener("storage", script) Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;
1 min read
HTML | DOM touchend Event
The touchend event is used to execute a script when a user removes his finger from an element. It will only work on devices with a touch screen. Supported Tags All HTML element supported by this event. Syntax: object.ontouchend = myScript; Below program illustrates the touchend event : Example-1: Executing a JavaScript when the user releases the to
1 min read
HTML | DOM timeStamp Event Property
The timeStamp Event property is used to get the timestamp of when a particular event is created. It basically returns the difference in time (in milliseconds) between the time of event created by the browser and January 1, 1970. It is a read-only property. Syntax: event.timeStamp Return Value: : This event returns the number of milliseconds since J
1 min read
HTML DOM stopPropagation() Event Method
The stopPropagation() method is used to stop the propagation of event calling. That is a parent event is called we can stop the propagation of calling its children by using the stopPropagation() method and vice-versa. Syntax: event.stopPropagation() Return Value: It does not return any value. Example: In this example when the checkbox is not checke
2 min read
HTML | DOM cancelable Event Property
The cancelable Event property is used to indicate whether or not an event can have its default actions prevented. If the default actions can be prevented the value is true, else the value is false. It is a read-only property. Syntax: event.cancelable Return Value: It returns a Boolean which indicates whether the event is cancelable or not. It retur
1 min read
HTML DOM type Event Property
The type event property in HTML DOM is used to return the type of the triggered event. It returns a string that represents the type of the event. The events can be keyboard events or mouse events. Syntax: event.type Return Value: It returns a string that represents the type of event. Example: In this example, we will use DOM type Event Property C/C
1 min read
HTML | DOM touchstart Event
The touchstart event is used to execute a script whenever the user touches an HTML element. On touching a particular element, if the touchstart event is associated with it, it can be used to trigger a javascript function. Note: The touchstart event works only on touch screen devices.Supported Tags All HTML element supported this event. Syntax : obj
1 min read
HTML DOM onpause Event
The DOM onpause event occurs when the audio/video is paused. The audio/video can be paused either by the user or programmatically. Supported Tags &lt;audio&gt; &lt;video&gt; Syntax: In HTML: &lt;element onpause="myScript"&gt;In JavaScript: object.onpause = function(){myScript};In JavaScript, using the addEventListener() method: object.addEventListe
1 min read
HTML DOM onabort Event
The DOM onabort event occurs in the abortion of an audio/video loading. This event occurs when the downloading of media data is aborted without any error. Events that occur when some disruption comes in the media loading process are: onemptiedonerroronstalledonsuspend Supported Tags &lt;audio&gt; &lt;video&gt; Syntax: HTML: &lt;element onabort="myS
1 min read
HTML | DOM onsuspend Event
The onsuspend event in HTML DOM occurs when the browser not getting media data. This event occurs when the media loading is suspended. This can happen when the download has completed, or it has been paused because of some interruption.Events that occurs when some kind of disturbance comes in the loading process: onabortonemptiedonerroronstalled Sup
1 min read
HTML DOM oninvalid Event
The HTML DOM oninvalid event occurs when we submit an invalid element. For example, if an input field is submittable and the required attribute is set then it's invalid if the field is empty. Syntax: In HTML:&lt;element oninvalid="myScript"&gt;In JavaScript:object.oninvalid = function(){myScript};In JavaScript, using the addEventListener() method:o
2 min read
HTML DOM onfocus Event
The HTML DOM onfocus event occurs when an element gets focused. The onfocus event is mostly used with &lt;input&gt;, &lt;select&gt;, and &lt;a&gt;. The onfocus event is the opposite of the onblur event. Syntax: In HTML:&lt;element onfocus="myScript"&gt;In JavaScript:object.onfocus = function(){myScript};In JavaScript, using the addEventListener() m
2 min read
HTML DOM ondrop Event
The HTML DOM ondrop event occurs when a draggable element is dropped on a valid drop target. There are some events that are used and occurred in the different stages of a drag-and-drop operation: Events fired on the draggable target: ondragstart: occurs when dragging of an element started.ondrag: occurs while an element is dragging.ondragend: occur
3 min read
HTML DOM ondurationchange Event
The HTML DOM ondurationchange Event occurs when the audio/video duration is changed. The duration of the audio/video is changed from "NaN" to the actual duration of the audio/video when it loads. The following events occur During the loading process of an audio/video: onloadstartondurationchangeonloadedmetadataonloadeddataonprogressoncanplayoncanpl
2 min read
HTML DOM ondragenter Event
The HTML DOM ondragenter Event occurs when a draggable element enter in valid drop target. The ondragenter and ondragleave events can help the user to understand the dropzone. There are some events that are used and occurred in the different stages of a drag and drop operation: ondragstart: occurs when dragging of an element started.ondrag: occurs
4 min read
HTML DOM ondragend Event
The HTML DOM ondragend event occurs when a draggable element finishes dragging. There are some events that are used and occurred in the different stages of a drag-and-drop operation: ondragstart: occurs when dragging of an element started.ondrag: occurs while an element is dragging.ondragend: occurs when dragging of an element finished. ondragenter
3 min read
HTML DOM ondblclick Event
The HTML DOM ondblclick event occurs on a double click by the user. All HTML elements are supported with ondblclick Event, EXCEPT: &lt;bdo&gt;&lt;br&gt;&lt;base&gt;&lt;head&gt;&lt;html&gt;&lt;iframe&gt;&lt;meta&gt;&lt;param&gt;&lt;script&gt;&lt;style&gt;&lt;title&gt;. Syntax: In HTML: &lt;element ondblclick="myScript"&gt; In JavaScript: object.ondb
2 min read
HTML DOM oncut Event
The HTML DOM oncut Event occurs when the content of an element is cut by the user. The oncut event is mostly used on elements with type="text". Supported Tags It supports all HTML elements. Syntax: In HTML: &lt;element oncut="myScript"&gt; In JavaScript: object.oncut = function(){myScript}; In JavaScript, using the addEventListener() method: object
2 min read
HTML DOM oncopy Event
The HTML DOM oncopy event occurs when the content of an element is copied by the user. It is also applicable to the image, created with the element. It is mostly used with type=”text”. Note: There are three ways to copy the content of an element: Press CTRL + CSelect "Copy" from the Edit menu in your browserRight-click to display the context menu a
2 min read
Article Tags :