I am trying to create a simple animation. In short, I have a list of 20 small divs and one outer div. I want to display five small divs within a large div at that time. Ideally, I get a set of the following 5 sections every 5 seconds.
I am using the jquery ajax function to create small divs, here is the code:
$(document).ready(function(){ var amount=0; $.ajax({ type: "GET", url: "SampleServiceIncidentList.xml", dataType: "xml", success: function(xml){ //creates divs within GadgetMain div, works fine. }); amount = $("#gadgetMain").children().size(); //counts how many small divs there are $("#testText").append("amount of children:"+amount); //and displays it in a test field divideFeed(); }//close success }); //close $.ajax( function divideFeed(){ //divides the set of small divs into groups var limit = 5; var pagesNo = Math.ceil((amount/limit)); var minimum=0; var maximum; var i=0; while (i<pagesNo) { minimum= i*limit; maximum=minimum+limit; // // PROBLEM HERE // populate(minimum, maximum); i++; } } function populate(minimum, maximum){ $("#gadgetMain div").addClass('hidden'); //hides all small divs $("#testText").append('<br/>min: '+minimum+' max: '+maximum); //prints current group of divs (0-5; 5-10 etc) $("#gadgetMain div").slice(minimum,maximum).removeClass('hidden'); }
});
So, the problem is that I can not make it wait 5 seconds to display a group of divs that interest me. I know that it divides divs correctly - when I warn about the minimum and maximum value, it changes the contents of the external div every time I close the warning. But I can not find a way to pause the function.
I would be very grateful for the help, it drove me crazy.
source share