$.cycle 和点击事件后的动态内容
我想将循环应用于具有动态内容的 div 块。该内容将在点击事件后生成。一旦我单击图像,它就可以工作,之后就无法工作。
代码:
$("div.cls img").click(function() {
.... Adding the content
$('#myDiv').cycle({
fx: 'scrollHorz',
speed: 3500,
timeout: 0, continuous: true,
pause: 1, sync: 1
});
});
HTML:
<div id="myDiv">
<div>
<a id="i1"> abc</a>
<a id="i2"> abcd</a>
<a id="i3"> abce</a>
<a id="i4"> abcf</a>
<a id="i5"> abcg</a>
<a id="i6"> abch</a>
</div>
<div>
<a id="i11"> abc1</a>
<a id="i21"> abcd1</a>
<a id="i31"> abce1</a>
<a id="i41"> abc1f</a>
<a id="i51"> abcg1</a>
<a id="i61"> abch1</a>
</div>
</div>
I want to apply cycle to the div block with dynamic content. This content will be generated after a click event. Once i click the image it is working after that it is not working.
Code:
$("div.cls img").click(function() {
.... Adding the content
$('#myDiv').cycle({
fx: 'scrollHorz',
speed: 3500,
timeout: 0, continuous: true,
pause: 1, sync: 1
});
});
HTML:
<div id="myDiv">
<div>
<a id="i1"> abc</a>
<a id="i2"> abcd</a>
<a id="i3"> abce</a>
<a id="i4"> abcf</a>
<a id="i5"> abcg</a>
<a id="i6"> abch</a>
</div>
<div>
<a id="i11"> abc1</a>
<a id="i21"> abcd1</a>
<a id="i31"> abce1</a>
<a id="i41"> abc1f</a>
<a id="i51"> abcg1</a>
<a id="i61"> abch1</a>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
添加动态内容后尝试再次调用
$.cycle()
。另外,使用 Firebug 确保您的内容正确生成。如果这不起作用,那么看起来您将不得不修改循环插件以支持动态添加“幻灯片”,或者编写您自己的解决方案。
来自 http://www.malsup.com/jquery/cycle/:
因此,您可以保留 Javascript,但 HTML 应该如下所示:
另外,一页上不应该有多个具有相同 ID 的元素。
EDIT:
Try calling
$.cycle()
again after adding your dynamic content. Also, use Firebug to ensure that your content is being generated correctly.If that doesn't work, then it looks like you will have to modify the cycle plugin to support dynamically adding "slides", or write your own solution.
From http://www.malsup.com/jquery/cycle/:
So, you can leave your Javascript alone, but the HTML should look like this:
Also, you should never have more than one element on a page with the same ID.