2013-02-16 21 views
1

我想实现和定制jQuery工具可滚动插件的行为有点。我想要的是在将滑动到下一个项目之前调用函数,等待函数完成,然后滑动到下一个项目。jquery工具可滚动onBeforeSeek函数,然后滑动到下一个

我尝试了从API的onBeforeSeek功能,但遗憾的是叫我需要的功能(如f.ex.的setTimeout),不等待它完成,它会立即滑动到下一个项目。

有人有任何想法,我可以防止滑到下一个项目,直到一个功能完成?它不必完全通过onBeforeSeek发生,但在我看来,它总结了触发prev/next的几个事件的结果。

标记:

<section> 
    <div> 
     <dl> 
      <dt>titre 1</dt> 
      <dd><img src="http://placehold.it/350x150"></dd> 
     </dl> 
     <dl> 
      <dt>titre 2</dt> 
      <dd><img src="http://placehold.it/350x150"></dd> 
     </dl> 
     <dl> 
      <dt>titre 3</dt> 
      <dd><img src="http://placehold.it/350x150"></dd> 
     </dl> 
    </div> 
</section> 

<!-- navigation (cubes) --> 
<div class="navi"></div> 
<br style="clear: both;"> 

<!-- navigation prev/next --> 
<a class="prev browse left">prev</a> | <a class="next browse right">next</a> 

JS:

$('section').css('overflow', 'hidden'); 

$('section').scrollable({ circular: true }).navigator(); 

var api = $('section').data("scrollable");//get access to the api functions 

api.onBeforeSeek(function(){ 

    //do something and after this start sliding to the next img 

} 

http://jsfiddle.net/micka/zhDGC/

在连接到API的小提琴奇怪的是使滑块休息...

任何建议,可以帮帮我。谢谢! 迈克尔

回答

0

编辑

所以,基本上你想达到什么是暂停onBeforeSeek事件,做你的东西,然后重新启动它。为此,你可以使用一些jQuery插件(简单的谷歌“jquery事件暂停简历”),其中一个可以找到here

如果你不想使用任何插件或不想处理事件,你可以使用我的解决方案在这个fiddle。而不是冻结,然后重新启动事件它只是第一次取消它,动画,更改动画状态完成,然后再次触发它,但这次没有事件取消。

var event_pos_list = [false, false, false]; 

api.onBeforeSeek(function(event, pos){ 
    // if the animation is not done - do it and skip the scroll 
    if(!event_pos_list[pos]){ 
     event.preventDefault(); 
     $('span').animate({marginLeft: (pos*50) + 'px'}, 2000, function(){ 
      // do the scroll, this time the animation is completed 
      event_pos_list[pos] = true; 
      api.seekTo(pos); 
     }); 
    } 
}); 
api.onSeek(function(event, pos){ 
    // after the scroll is done, reset the event_pos_list 
    event_pos_list[pos] = false; 
}); 

希望这会有所帮助。

+0

这与用'api.onBeforeSeek(function(){...})连接到api相同' 这并不帮助我,我很抱歉。 如上所述,当我点击下一个按钮时,我想调用一个函数,当这个函数完成时,滑动到下一个项目。 – MichaelKaeser 2013-03-08 18:45:49

+0

请检查更新的小提琴。你错过了尾部支架。 http://jsfiddle.net/zhDGC/17/ – iurii 2013-03-09 10:28:17

+0

这仅适用于警报功能。警报发生时,所有操作都会被阻止。但请查看相同的例如动画:http://jsfiddle.net/zhDGC/18/,它不会等待动画完成切换到下一个项目... – MichaelKaeser 2013-03-10 10:58:35

相关问题