admin管理员组

文章数量:1356861

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.replace('#!','');  

$newLoc = "#"+$newLoc;

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

here's the site FYI /

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.replace('#!','');  

$newLoc = "#"+$newLoc;

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

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

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Aug 29, 2011 at 17:15 Greg ThompsonGreg Thompson 8944 gold badges13 silver badges33 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 7

I've had the same problem, but I found the solution here http://usejquery./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 pletes. 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); 
});

本文标签: javascriptJquery scrollTo prevent queueStack Overflow