I’m using Cycle to attempt to cycle through some divs that are generated by another jQuery function. Here’s the function:
$.getJSON('../functions.php', function(images) {
$.each(images, function() {
$('#slideshow').append('<div class="slide" style="background-image:url(' + this + ');"></div>');
});
});
I’m having a weird issue. The DIVs are appearing, and if I use the Chrome Inspector I can see them, but they don’t show up if I view the source explicitly. Maybe that doesn’t matter, but when I run:
$('#slideshow').cycle();
I get an error in the console that says:
[cycle] terminating; too few slides: 0
You can see the site live here: http://new.element17.com
Any idea why this is happening?
The reason for that is that you’re populating your slideshow images using
getJSONmethod.Even though this method is located before you cycle method,
getJSONis asynchronious method that’s why cycle is running before loading images.Solutions:
1. Use
.ajaxinstead of.getJSONwithasync: false2 Move
$('#slideshow').cycle();inside.getJSONmethod so it run after loading images.This code is not tested