Menu Close

How to Detect Scroll up and Scroll Down event on Page with jQuery


Let’s see how to detect scroll up or scroll down on your page using jQuery. This action is based on the direction of scrolling.


<!DOCTYPE html>
    <title>Print PDF using inline iFrame</title>
<body style="height:1000px">
    <p class="down" style="position: fixed;display: none;">Moving Down</p>
    <p class="up" style="position: fixed;display: none;">Moving Up</p>
<script src=""></script>
	 var lastScrollTop = 0, threshold = 5;
		 var nowScrollTop = $(this).scrollTop();
		 if(Math.abs(lastScrollTop - nowScrollTop) >= threshold){
		 	if (nowScrollTop > lastScrollTop){
		 	} else {
		 lastScrollTop = nowScrollTop;

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?


Posted in jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *

You can also read...