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;
Posted in jQuery

You can also read...