From jQuery JavaScript Library
« Back to Events
scroll( fn )
Bind a function to the scroll event of each matched element.
The scroll event fires when a document view is scrolled.
Arguments:| fn | Function | |
|---|
A function to bind to the scroll event on each of the matched elements.
function callback(eventObject) {
this; // dom element
}
|
Examples:| Name | Type |
To do something when your page is scrolled:
$("p").clone().appendTo(document.body);
$("p").clone().appendTo(document.body);
$("p").clone().appendTo(document.body);
$(window).scroll(function () {
$("span").css("display", "inline").fadeOut("slow");
});
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("p").clone().appendTo(document.body);
$("p").clone().appendTo(document.body);
$("p").clone().appendTo(document.body);
$(window).scroll(function () {
$("span").css("display", "inline").fadeOut("slow");
});
});
</script>
<style>
div { color:blue; }
p { color:green; }
span { color:red; display:none; }
</style>
</head>
<body>
<div>Try scrolling the iframe.</div>
<p>Paragraph - <span>Scroll happened!</span></p>
</body>
</html>