Attach a function to the scroll event: - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:scroll

Description

Attach a function to the scroll event:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
x = 0;//  w w w  .ja va 2s.c o m
$(document).ready(function(){
    $("div").scroll(function(){
        $("span").text( x+= 1);
    });
});
</script>
</head>
<body>

<p>Try the scrollbar in the div</p>

<div style="border:1px solid black;width:200px;height:100px;overflow:scroll;">
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
<br><br>
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
<br><br>


</div>

<p>Scrolled <span>0</span> times.</p>

</body>
</html>

Related Tutorials