开发者

Jquery scrollTo prevent queue

开发者 https://www.devze.com 2023-04-01 01:51 出处:网络
Ok simple question for scrollTo. I\'m looking for a way to prevent the queuing of the scroll animations. I\'ve tried to work in stop() but it doesn\'t seem to do the trick.. any Ideas? here\'s the cod

Ok simple question for scrollTo. I'm looking for a way to prevent the queuing of the scroll animations. I've tried to work in stop() but it doesn't seem to do the trick.. any Ideas? here's the code...

('#nav_hold li a').click(function(){

$currLoc = $(this).attr('href');

$newLoc = $currLoc.re开发者_如何学Pythonplace('#!','');  

$newLoc = "#"+$newLoc;

$(window).scrollTo($newLoc, 1000);

});

here's the site FYI http://www.dudnyk.com/files/connector/


I've had the same problem, but I found the solution here http://usejquery.com/sites/contrast-rebellion

Just use the line jQuery.scrollTo.window().queue([]).stop(); before any new scrollTo.


There is function clearQueue(). I think that should help.


.stop() Is for removing the currently running animation, to also clear to queue use .stop(true)

$('#about').click(function() {
    $(this).stop(true);
    $.scrollTo('#about', 1000); 
});

From jQuery Docs (linked above):

If more than one animation method is called on the same element, the later animations are placed in the effects queue for the element. These animations will not begin until the first one completes. When .stop() is called, the next animation in the queue begins immediately. If the clearQueue parameter is provided with a value of true, then the rest of the animations in the queue are removed and never run.


{ queue : false }

as the scrollTo option

but that's the default. doesn't the anchor click get you somewhere?


When you use $.scrollTo on any element it is actually scrolling(with animation) the document until the scroll reaches to the specified element. So I believe we should stop the animation on document. Try this

$('#about').click(function() {
    $(window).stop();
    $.scrollTo('#about', 1000); 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号