Learn html - html tutorial - Onscroll attribute in html - html examples - html programs
The onscroll attribute triggers when the element’s scrollbar is being scrolled.
onscroll attribute is the part of the event attribute.
Syntax for onscroll attribute in HTML:
<div onscroll="myFunction()">
Differences between HTML 4.01 and HTML5 for onscroll attribute:
HTML 4.01
HTML4 does not support onscroll attribute.
HTML 5
HTML5 supports onscroll attribute.
Applies To:
Element
Attribute
All Visible elements
onscroll
Attribute Values:
Value
Description
script
The script can run on onscroll
Sample Coding for onscroll Attribute in HTML:
Tryit<!DOCTYPE html><html><head><title>Wikitechy onscroll attribute</title><style>
#myDIV {
border: 1px solid black;
width: 300px;
height: 150px;
overflow: scroll;
}
</style></head><body><h3>Welcome to Wikitechy.com</h3><h5>Wikitechy technology tutorials</h5><p>To need more details scroll down:</p><div id="myDIV" onscroll="OnScroll()">Wikitechy tutorials includes various technologies like HTML,CSS,GITHUB,ANGULAR JS etc.,><br><br>
HTML - Hyper Text Markup Language.HTML is a typical markup language used for building a web pages.
The word "Markup" means a language with particular syntax which instructs a Web browser to how the
page needs to display.HTML uses a pre-defined set of elements called tags. A group of elements
which is join together to build the web page.HTML tags defines elements like "paragraph",
"body", and so on.
</div><script>
function OnScroll()
{
document.getElementById("myDIV").style.color = "blue";
}
</script></body></html>
Code Explanation for onscroll Attribute in HTML:
“myDIV” is used to apply styles to the
element.
<div id=”myDIV”> is used to display block of contents with specified style.
The onscroll attribute is used to call OnScroll() JavaScript function when the content inside the scrollbar is scrolled.
The JavaScript function OnScroll() is used to display the content in blue color when scrolled.
Output for onscroll Attribute in HTML:
The output shows the contents.
When user scroll downwards the text turns into blue color.