
Untitled
By: a guest on
Jun 13th, 2012 | syntax:
None | size: 1.48 KB | hits: 15 | expires: Never
load() sequentially, instead of at the same time with jQuery
$('nav a').each(function(index){
var to_load = $(this).attr('href') + '#slides section';
$('<section>').load(to_load, function(){
$('#slides').append($(this).html());
});
});
$(this).attr('href') + '#slides section'
this.href + '#slides section'
var loadTos = [];
$('nav a').each(function(index){
loadTos.append($(this).attr('href') + '#slides section');
});
function load_link(to_load) {
$('<section>').load(to_load, function(){
$('#slides').append($(this).html());
loadTos.length && load_link(loadTos.pop());
});
}
if(loadTos.length) {
loadTos = loadTos.reverse(); // make getting urls from first to last
load_link(loadTos.pop());
}
var i = -1; // this is because we will increment the value before using it
var collection = $('nav a');
function loadNext() {
i++;
if (i < collection.length) {
var to_load = $(collection[i]).attr('href') + '#slides section';
$('<section>').load(to_load, function(){
$('#slides').append($(this).html());
loadNext();
});
}
}
loadNext();
// grab array of links
var links = $('nav a').map(function() {
return this.href;
}).get();
function loadSlides() {
$('<section>').load(links[0] + '#slides section', function() {
$('#slides').append($(this).html());
// remove first item of links array
links.shift();
loadSlides();
});
}
loadSlides();