jQuery scroll event

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

In this video we will discuss scroll event and how to handle it using jQuery.

scroll event is raised when the user scrolls to a different place in the element. It applies to window objects, but also to scrollable frames and elements with the overflow CSS property set to scroll.

In the following exampe, notice that the div element overflow style is set to scroll. The div element has a scrollbar and as you scroll up and down the div element, the scroll event is raised and handled.

Replace < with LESSTHAN symbol and > with GREATERTHAN symbol

<html>
<head>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
$('div').scroll(function () {
$('h3').css('display', 'inline').fadeOut(1000);
});
});
</script>
</head>
<body style="font-family:Arial">
<div style="width:300px; height:200px; border:1px solid black; overflow:scroll">
PRAGIM Speciality in training arena unlike other training institutions. Training delivered by real time software experts having more than 10 years of experience. Interview questions and real time scenarios discussion on topics covered for the day. Realtime projects discussion relating to the possible interview questions. Trainees can attend training and use lab untill you get a job. Resume preperation and mock up interviews. 100% placement assistance. 24 hours lab facility. PRAGIM Technologies offers professional real time projects for studetns in their final semester. Course completion and project completion certificates will also be provided upon successful completion of the course. We have partnered with major multinational companies to place freshers with our clients on their course completion.
</div>
<br />
<h3 style="display:none; color:red">Scroll event handled</h3>
</body>
</html>

The following example, keeps track of how many times the scroll event is raised.

<html>
<head>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
var count = 0;
$('div').scroll(function () {
$('span').text(count += 1);
});
});
</script>
</head>
<body style="font-family:Arial">
<div style="width:300px; height:200px; border:1px solid black; overflow:scroll">
DIV CONTENT
</div>
<br />
<h3 style="color:red">Scroll event handled <span>0</span> time(s)</h3>
</body>
</html>

The following example, keeps track of whether the user scrolled up or down.

<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
var lastScrollTop = 0;
$('div').scroll(function () {
var currentScrollPosition = $(this).scrollTop();
if (currentScrollPosition > lastScrollTop) {
$('h3').text('You scrolled down');
} else {
$('h3').text('You scrolled up');
}
lastScrollTop = currentScrollPosition;
});
});
</script>
</head>
<body style="font-family:Arial">
<div style="width:300px; height:200px; border:1px solid black; overflow:scroll">
DIV CONTENT
</div>
<br />
<h3 style="display:inline; color:red"></h3>
</body>
</html>
Рекомендации по теме
Комментарии
Автор

This is the by far the best jquery tutorial available on youtube

AmitKumar-nnrr
Автор

Thank you for this tutorial
I just discovered the huge possibilities that can be done with the scrollbar

revxlzions
Автор

Amazing video. Your tutorials are by far the best

biswadip
Автор

I always learn something from your videos, thank you.

kaminari
Автор

Thank you Sir, I have watched your videos of JavaScript and jQuery, they are so helpful. Will you plan to prepare the AJAX tutorial?

boi-huela
Автор

Fantastic tutorial, very useful stuff! :)

TheMalni
Автор

it was really awsome stuff!! will help alot...

Just_Bunny_life
Автор

how to load data in the datalist on page scroll depending upon the selection...like in shopping sites using jquery

kewataniruddh
Автор

i want to know sir is there any event name of wheelrolling to fowrd and backword?
i mean at the time of wheel rotate for up side and down side...

Indranilgslv
Автор

Hello man .. I need cours for How to build a scrolling list with jQuery
Please help me

KingArb
Автор

lastscrolltop =currentscrollposition; why you type this last

ahammedshibil