Reputation: 41605
I am trying to create an scrolling animation when the user moves the mouse wheel up or down, press the the keyword arrows or move the scrolling bar in the side.
It is pretty similar as what I found on this site. As I didn't find any jQuery plugin for it, I am trying to reproduce it by my own and I am having some troubles with the scrolling behavior.
When the scrolling animation is taking place, you can still scrolling with the mouse wheel and it makes the movement look ugly, going up and down for a while.
Here's my fiddle where you can check it: http://jsfiddle.net/k4rsN/1/
The problem is that the scrolling is not disable and before I can check if they are scrolling up or down, the site has already scrolled a bit (a movement of the wheel, or keyword). Therefor I believe the way to solve it is disabling the scrolling effect and letting me decide what to do when the user decides to scroll.
I've been taking a look at posts like this or this but it don't solve my problem.
This is what I've done so far as you can see in the fiddle:
var lastScrollTop = 0;
var isMoving = false;
$(window).scroll(function () {
var currentScroll = $(window).scrollTop();
//scrolling down?
if (currentScroll > lastScrollTop && !isMoving) {
var value = '#link2';
}
//scrolling up?
else if (!isMoving) {
var value = '#link1';
}
lastScrollTop = currentScroll;
//animation
if (value && !isMoving) { //if theres any #
isMoving = true;
dest = $(value).offset();
$('html, body').animate({
scrollTop: dtop
}, 1200, function () {
//setting the flag to avoid checking the scrolling when performing the animation
isMoving = false;
});
}
});
Thanks.
Upvotes: 2
Views: 3315
Reputation: 235
At the beginning of your function, you could apply some CSS attributes to make it unscrollable. Then at the end of your animation, revert it back to normal. For example:
At the beginning of your animation
$('html, body').css({
'overflow': 'hidden',
'height': '100%'
})
Then, at then end
$('html, body').css({
'overflow': 'auto',
'height': 'auto'
})
This is virtually the same thing as this answer: https://stackoverflow.com/a/17293689/2247151
Upvotes: 1