Cycle2初始化事件未触发

编程入门 行业动态 更新时间:2024-10-26 13:26:20
本文介绍了Cycle2初始化事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将Cycle2用于基本的轮播.我的幻灯片项目有时在其数据中有一个url,因此我必须使用Cycle2 api事件在该URL处使用它.

I'm using Cycle2 for a basic carousel. My slide items sometimes have a url in their data, so I have to use the Cycle2 api events to use that url when it is there.

我的问题是,虽然'cycle-after'事件可以正常运行,但没有初始化事件可以触发.因此,如果我的第一张幻灯片具有网址,则什么也不会发生.这是我的代码:

My problem is that while the 'cycle-after' event fires fine, none of the initialize events will fire. So if my first slide has a url, nothing happens. This is my code:

pressSlideshow.on({ 'cycle-post-initialize': function(event) { console.log('call'); var a = $('img.cycle-slide-active'); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } }, 'cycle-after': function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) { var a = $(incomingSlideEl); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } } });

第一个事件永远不会触发,但是当我滚动幻灯片放映时,"cycle-after"事件运行良好.我还尝试了从未触发的'cycle-initialized'事件和仅在滚动后触发但未在初始化时触发的'cycle-update-view'事件.

The first event never fires but when I scroll the slideshow the 'cycle-after' event works fine. I've also tried the 'cycle-initialized' event which never fired, and the 'cycle-update-view' event which only fired after scroll but not on initialization.

有什么作用? &提前thnx:}

What gives? & thnx in advance :}

Cycle2事件文档

推荐答案

我也遇到了同样的问题.

I just had this same problem.

来自常见问题解答

为什么周期初始化的事件不触发?

我保证.但 如果您在触发事件监听器后将其绑定,则您 听不到.仔细检查您的绑定时间是否太晚. Why doesn't the cycle-initialized event fire?

It does, I promise. But if you bind your event listener after it has already fired then you won't hear it. Double check that you're not binding too late.

在运行cycle()初始化方法之前,必须绑定事件.

You must bind the event before you run the cycle() init method.

假设您的代码设置如下:

Assuming that your set up your code like:

var pressSlideshow = $('.pressSlideshow').cycle(); pressSlideshow.on({ 'cycle-post-initialize': function(event) { console.log('call'); var a = $('img.cycle-slide-active'); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } }, 'cycle-after': function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) { var a = $(incomingSlideEl); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } } });

执行此操作:

$(document).on('cycle-post-initialize', '.pressSlideshow', function(){ console.log('call'); var a = $('img.cycle-slide-active'); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } }); var pressSlideshow = $('.pressSlideshow').cycle(); pressSlideshow.on({ 'cycle-after': function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) { var a = $(incomingSlideEl); var d = a.data('url'); if (d !== undefined) { pressLink.attr('href', a.data('url')).show(); } else { pressLink.hide(); } } });

请注意.pressSlideshow选择器,因为您的选择可能有所不同.

Take note of the .pressSlideshow selector as yours could differ.

欢呼

更多推荐

Cycle2初始化事件未触发

本文发布于:2023-11-04 01:22:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!