English 中文(简体)
jQuery - ScrollTo and Serial Scroll not working together
原标题:

I have tested the scrollTo() plugin, but I need a way to stop the scrolling animation, so I am looking at serialScroll().

Here is what I used with scrollTo:

$( #scroller ).scrollTo( 1000px , 3000);

My question is, how do I do this same thing with serialScroll? I can t get it to work the same way as scrollTo, isn t that what it is suppose to do, just add tons of extra options?!

最佳回答

As SerialScroll binds several events (incuding thestop event) you can use toggle to start/stop the scrolling based on clicks:

// setup serialScroll to scroll the images in the  serialScroll-test  div along
// the y-axis.
$( #serialScroll-test ).serialScroll({items:  img , duration: 2000, axis:  y , interval: 1, force: true});
// since we used the "force: true" option to auto-start the animation we use
// "stop" as the first function to toggle and "start" second.
$( #serialScroll-test ).toggle(function(){ 
  $( #serialScroll-test ).trigger( stop.serialScroll ); 
}, function() { 
  $( #serialScroll-test ).trigger( start.serialScroll ); 
});

On the following HTML:

  <div id="serialScroll-test" style="float: left; width: 600px; height: 333px; overflow: hidden;"> 
    <img class="scrollable" src="http://farm4.static.flickr.com/3489/3849497254_4722754872.jpg" alt="IMG_7997" /> 
    <img class="scrollable" src="http://farm3.static.flickr.com/2487/3867263002_f6b368d983.jpg" alt="IMG_8005" /> 
    <img class="scrollable" src="http://farm3.static.flickr.com/2528/4043006363_81931d7985.jpg" alt="IMG_2235" /> 
  </div> 

Example (edit the source)

note: when the stop event is called the animation stops on the item being scrolled to, not immediately. So if you click on the first image while it is scrolling to the second one the animation will continue till the second image is in view and then stop. This also means that when using cycle: true (the default) if you click during the return to the first image the animation will continue till the first image is in view and then stop.

EDIT:

After looking a bit deeper I found this post on Ariel Flesler s blog (the plugins author). In the snippets section a script is included on how to stop the animation on hover. It includes a note:

// You can temove the .stop() to let it finish the active animation
...
   $(this).stop().trigger( stop );
...

Notice the additional stop() in the trigger. Based on the code I posted above you can change the toggle() function to:

$( #serialScroll-test ).toggle(function(){ 
  $( #serialScroll-test ).stop().trigger( stop.serialScroll ); 
}, function() { 
  $( #serialScroll-test ).stop().trigger( start.serialScroll ); 
});

to produce the desired effect. Updated example here (edit it)

问题回答

暂无回答




相关问题
how to detect Android ListView Scrolling stopped?

I m trying to do something after scrolling stopped.So, I tried using OnScrollListener#onScrollStateChanged(SCROLL_STATE_IDLE) to detect when the scrolling stopped(either TOUCH_SCROLL or FLING)(at 1.5 ...

jQuery - ScrollTo and Serial Scroll not working together

I have tested the scrollTo() plugin, but I need a way to stop the scrolling animation, so I am looking at serialScroll(). Here is what I used with scrollTo: $( #scroller ).scrollTo( 1000px , 3000); ...

Scrolling to the bottom of a div

As part of an ajax chat room (using prototype framework) I am working on I scroll the user to the bottom each time a message is added using the below js. However if the user has scrolled up and the ...

Displaying news with javascript

I keep coming up against this issue. Displaying news on a website. And I d like to come up with a solution to use like a template, something I can just drop on a site easily. The solution I keep ...

UITextview content moves up when textview is selected

I am pretty new to this iPhone dev thing but so far I have built a pretty good app but I have stumbled into this problem that for the life of me I cannot seem to solve. Basically the app is a chat ...

热门标签