Jquery Cycle 插件,内容更改时更新滑块,问题!
我刚刚尝试了 Mike Alsup 的 Cycle 插件。对于我正在构建的页面来说,看起来足够简洁和简单。但现在,我遇到了一个问题。
我正在将 Cycle 应用于图像列表。现在,我尝试销毁并重新应用该插件,但没有成功。
当内容更改时,我触发 ('destroy');
并再次应用插件:
$('#slides').cycle('destroy');
$('#slides').cycle({
fx: 'fade',
speed: 'fast',
timeout: 0,
next: '#next',
prev: '#prev'
});
这适用于:
<div id="display">
<a href="#" id="prev">Previous</a>
<a href="#" id="next">Next</a>
<div class="imgcontainer">
<ul id="slides">
> List of images to go into slideshow. <
</ul>
</div>
<div class="infocontainer">
<h2> Object title </h2>
<p> Object information </p>
</div>
</div>
一切看起来都很好,直到我在更新滑块后尝试更改图像:
类型错误:“null”不是对象(正在评估“p.cycleTimeout”)
整个 JavaScript;
$('#projects > li').click(function(){
var a = $(this);
$('#display .imgcontainer ul').html((a).children('ul.images').html());
$('#display .infocontainer h2').html((a).children('h2').html());
$('#display .infocontainer p').html((a).children('p').html());
if(!$(a).hasClass('sub'))
{
var title = $(this).attr('title');
$(a).siblings("[title='" + title + "']").toggle();
}
var imgcount = $('.imgcontainer li').size();
// Only apply plugin if there's more than one image in the list.
if(imgcount > 1)
{
$('#slides').cycle('destroy');
$('#slides').cycle({
fx: 'fade',
speed: 'fast',
timeout: 0,
next: '#next',
prev: '#prev'
});
}
});
I've just tried out Mike Alsup's Cycle Plugin. Seems lite and easy enough for a page I'm building. Now though, I've run into a problem.
I'm applying Cycle to a list of images. Now, I've tried to destroy and reapply the plugin, though with no success.
I trigger ('destroy');
when the content changes and apply the plugin again with:
$('#slides').cycle('destroy');
$('#slides').cycle({
fx: 'fade',
speed: 'fast',
timeout: 0,
next: '#next',
prev: '#prev'
});
And this applies to:
<div id="display">
<a href="#" id="prev">Previous</a>
<a href="#" id="next">Next</a>
<div class="imgcontainer">
<ul id="slides">
> List of images to go into slideshow. <
</ul>
</div>
<div class="infocontainer">
<h2> Object title </h2>
<p> Object information </p>
</div>
</div>
Everything seems fine until I try to change image after updating the slider:
TypeError: 'null' is not an object (evaluating 'p.cycleTimeout')
The javascript in whole;
$('#projects > li').click(function(){
var a = $(this);
$('#display .imgcontainer ul').html((a).children('ul.images').html());
$('#display .infocontainer h2').html((a).children('h2').html());
$('#display .infocontainer p').html((a).children('p').html());
if(!$(a).hasClass('sub'))
{
var title = $(this).attr('title');
$(a).siblings("[title='" + title + "']").toggle();
}
var imgcount = $('.imgcontainer li').size();
// Only apply plugin if there's more than one image in the list.
if(imgcount > 1)
{
$('#slides').cycle('destroy');
$('#slides').cycle({
fx: 'fade',
speed: 'fast',
timeout: 0,
next: '#next',
prev: '#prev'
});
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一次,即使从未应用过循环,您也会调用“销毁”。这可能就是你的错误的来源。
无论如何,你不应该这样做。 Cycle 有一个专门用于此目的的
addSlide
函数。请参阅示例:The first time through, you're calling "destroy" even though cycle has never been applied. That's probably where your error is coming from.
You shouldn't be doing it this way, anyways. Cycle has an
addSlide
function specifically for this purpose. See the examples: