我的设置看起来像这样:
$(".slideshow").cycle({
slides: ".slide",
timeout: 0,
speed: 200,
swipe: true
}).on("cycle-before", function(e, opts, outgoing, incoming, forwardFlag){
// trying to cancel event here when some condition is met!
});
我要做的是检查是否达到某张幻灯片,然后执行其他操作而不是转换到下一张幻灯片。
我尝试了return false
,e.stopPropagation()
,e.stopImmediatePropagation()
及其组合,但无论我做什么,幻灯片仍会继续播放到下一张幻灯片。
有没有办法从cycle-before
事件处理程序中取消转换到下一张幻灯片?
答案 0 :(得分:1)
一种方法是覆盖他们的cycle2内部API,如http://jquery.malsup.com/cycle2/api/advanced.php
所述只有在满足条件时才调用原始内部fn。它看起来像这样:
$( '#mySlideshow' ).on( 'cycle-bootstrap', function( e, optionHash, API ) {
// advanceSlide handles next, prev
var origAdvanceSlide = API.advanceSlide;
API.advanceSlide = function(n) {
if (<condition>) {
origAdvanceSlide.call(API,n);
}
}
// jump handles the goto a specific slide
var origJump = API.jump;
API.jump = function(n) {
if (<condition>) {
origJump.call(API,n);
}
}
});