|
|
The
onscroll event attribute in HTML triggers a script when an element's scrollbar is being scrolled. This attribute can be applied to any HTML element that has a scrollable overflow, typically achieved by setting the CSS overflow property to scroll, auto, or overlay. |
<div onscroll="myFunction()">
The onscroll attribute fires when an element's scrollbar is being scrolled.
Tip: use the CSS overflow style property to create a scrollbar for an element.
<element onscroll="script">
| Value | Description |
|---|---|
| script | The script to be run on onscroll |
| Supported HTML 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> |
|---|
Try the scrollbar in div.
A function is triggered when you scroll in div. The function sets the color of the text in div to red.
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
width: 200px;
height: 100px;
overflow: scroll;
}
</style>
</head>
<body>
<p>Try the scrollbar in div.</p>
<div id="myDIV" onscroll="myFunction()">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.
<br><br>
'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.'</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.color = "red";
}
</script>
<p>A function is triggered when you scroll in div. The function sets the color of the text in div to red.</p>
</body>
</html>
| html event attributes |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Drag Events Attribute |
Uploaded by: | Admin |
Read Articlehttps://develop.horje.com/learn/1434/reference