Reputation: 85545
I'm doing the following jquery for learning purpose. I wanted to increase the blue div width when scroll down and decrease when scroll up. Please suggest me where I'm doing wrong.
jQuery:
$(window).scroll(function () {
var last_scroll = $(window).scrollTop();
var current_scroll = $(window).scrollTop();
var changes_scroll = (current_scroll - last_scroll);
if (changes_scroll > 0) {
$("#slide").width('+=10%');
} else {
$("#slide").width('-=10%');
}
});
Upvotes: 0
Views: 160
Reputation: 10378
var last_scroll = $(window).scrollTop();
$(window).scroll(function () {
var current_scroll = $(window).scrollTop();
var changes_scroll = (current_scroll - last_scroll);
if (changes_scroll > 0) {
$("#slide").width('+=10%');
} else {
$("#slide").width('-=10%');
}
last_scroll = $(window).scrollTop();
});
Upvotes: 3
Reputation: 6938
var last_scroll = $(window).scrollTop();
var current_scroll = $(window).scrollTop();
If last_scroll and current_scroll are getting the same value assigned, changes_scroll
will allways be zero
Upvotes: 0