开发者

jQuery ScrollTo: Multiple clicks on link = funky movement stacking

开发者 https://www.devze.com 2023-01-20 04:19 出处:网络
Here is the开发者_运维百科 code: $(\'.next\').click(function(){ $(window).stop(true,true).scrollTo(\'+=800px\', 1000, { axis:\'x\' } );

Here is the开发者_运维百科 code:

$('.next').click(function(){
        $(window).stop(true,true).scrollTo('+=800px', 1000, { axis:'x' } );
 });
$('.prev').click(function(){
        $(window).stop(true,true).scrollTo('-=800px', 1000, { axis:'x' } );
 });

Site can be previewed here: http://www.allisonnavon.com/index.php?/projects/raw-rhythm/

When the » are clicked more than once, it queues them up, even with the stop(true,true) parameter. Anyone know why?


.stop() only affects the animation queue for that element, instead you can just .animate() in this case (no need for the scrollTo plugin here):

$('.next').click(function(){
  $("html, body").stop(true,true).animate({ scrollLeft: '+=800' }, 1000);
});
$('.prev').click(function(){
  $("html, body").stop(true,true).animate({ scrollLeft: '-=800' }, 1000);
});

This way the .stop() will effect the animation queue on those elements.

0

精彩评论

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