Reputation: 437
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'
});
}
});
Upvotes: 0
Views: 2901
Reputation: 239220
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:
Upvotes: 1