有谁知道如何为jQuery循环插件设置回调函数?
我知道您可以为某些操作设置各种回调,但我需要获取动态创建的寻呼机链接。我想使用innerHTML 将动态图像放入这些链接中,但如果我将其称为onload,它显然无法工作,因为链接尚未创建。
似乎没有可以为 jQuery 循环设置的本机“回调”函数。我错过了吗?即使插件本身不提供,有没有办法做到这一点?
谢谢!
I know that you can set various callbacks for certain actions, but I need to get at the pager links that get created on the fly. I want to drop dynamic images into those links using innerHTML, but if I call it onload it obviously won't work because the links haven't been created yet.
There doesn't seem to be a native "callback" function you can set for jQuery cycle. Am I missing it? Is there a way to do it even if the plugin doesn't provide it natively?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有很多事情。
首先,您可以使用传递给循环的 'pager' 选项指定分页选项的显示位置 - $('#myelement').cycle({pager: '#mypagerdiv'})。这将允许您稍后在 jQuery 中找到它们(例如 $('#mypagerdiv a'))。
其次,有大量可用于循环的回调,可以在此处的选项对象文档中找到: http://jquery.malsup.com/cycle/options.html
您可能最有可能对以下内容感兴趣: pagerAnchorBuilder
您将按如下方式使用它: $('#mycyclediv').cycle({ pagerAnchorBuilder: %yourfunction%})
使用此功能,您可以构建自己的分页器控件,并且可以在 jQuery 循环网站上找到有关如何执行此操作的一小部分示例:
jquery.malsup.com/cycle/pager2.html
jquery .malsup.com/cycle/pager3.html
jquery.malsup.com/cycle/pager7.html
jquery.malsup.com/cycle/pager11.html
这应该允许您需要的功能。
但是,如果您希望在更改幻灯片时更改这些动态图像,则可以使用“before”和“after”回调,它们分别在幻灯片转换发生之前和之后触发。
如果您还有任何其他问题,请随时与我们联系,尽管我发现 jQuery 循环文档相当广泛,并且“中级演示 2”应该会为您提供回调方面的正确方向的帮助。
(我是这里的新用户,因此无法发布多个超链接,对上述网址深表歉意)
There are a number of things here.
Firstly, you can specify where the paging options are displayed using the 'pager' option passed to cycle - $('#myelement').cycle({pager: '#mypagerdiv'}). This will allow you to find them in jQuery later ($('#mypagerdiv a'), for example).
Secondly, there are a multitude of callbacks available for cycle, which can be found in the options object documentation here: http://jquery.malsup.com/cycle/options.html
You are probably most likely to be interested in the following: pagerAnchorBuilder
You would use it as follows: $('#mycyclediv').cycle({ pagerAnchorBuilder: %yourfunction%})
Using this, you can build your own pager controls, and a small selection of examples of how to do this can be found on the jQuery cycle website:
jquery.malsup.com/cycle/pager2.html
jquery.malsup.com/cycle/pager3.html
jquery.malsup.com/cycle/pager7.html
jquery.malsup.com/cycle/pager11.html
This should allow for the functionality you need.
However, if you wish to change these dynamic images when slides are changed, then you can make use of the 'before' and 'after' callbacks, which are triggered before and after a slide transition occurs, respectively.
If you have any further questions, don't hesitate to get in touch, although I've found that the jQuery cycle documentation is quite extensive, and the "Intermediate demo 2" should give you a helpful nudge in the right direction re callbacks.
(I'm a new user here, so can't post more than one hyperlink, so sorry for above URLs)
我相信有一些关于如何使用回调的方便示例,以及此示例页面上的寻呼机项目 http://jquery.malsup.com/cycle/int2.html
选项参考中有所有可能的回调函数的详细列表 http://jquery.malsup.com/cycle/options.html
您可能需要关注的回调:
希望对您有所帮助
I believe there are some handy examples of how to use callbacks, as well as the pager item on this examples page http://jquery.malsup.com/cycle/int2.html
There is an extensive list of all of the possible callback functions in the Options reference http://jquery.malsup.com/cycle/options.html
The callbacks you might want to focus on:
hope that helps you out