malsup / cycle2

2nd gen cycling
898 stars 237 forks source link

ajax loaded slides appearing in wrong sequence #255

Closed avowkind closed 11 years ago

avowkind commented 11 years ago

I have

and a javascript ondocument function that calls a web service to find the list of image urls to load. This loops over the results calling:

imgNext = '<img src="'+url+'" ">' $("cycle-slideshow").cycle('add', imgNext);

Usually this works ok but sometimes some of the images take longer to be loaded by the browser than others. The cycler appear to play the images in the order they arrived rather than the order that the add function was called. In fact the cycler does not appear to add the statement to the DOM until the image has arrived.

I've tried this with data-cycle-loader="true" but no difference.

Is this a bug, or by design?

Thanks Andrew

malsup commented 11 years ago

That's not how the "wait" functionality works. Using "wait" will cause the slideshow to delay initialization until all of the existing slide images can be loaded. In your case, there are zero slides when the slideshow is initialized. In your case you may wish to avoid using the auto-init feature (don't use cycle-slideshow class) and instead initialize manually after injecting your image slides:

for ( /* loop over image array */ )  {
    imgNext = '<img src="'+url+'" ">'
    $(".slideshow").append(imgNext);
}
$(".slideshow").cycle();