I am using this script…
It load content from a specifc #id in a URL to current page, and animate it… sliding from side of the page…when user click on a link
Everything works except images taking time to load… I tried and struggling to incorporate image preloader to this? So all the content loads together
function goTo(href) {
var left = $(window).width();
$('#id').css("left", left);
$.ajax({
url: href,
success: function (data) {
var content = $(data).find('#id').html();
// Windows Load Function
$(window).load(function () {
$("#id").html(content).animate({
left: '0',
}, 'fast');
var title = $('#id').find('h1').text();
$('head').find('title').text(title);
});
}
});
}
// check for support before we move ahead
if (typeof history.pushState !== "undefined") {
var historyCount = 0;
// On click of link Load content and animate
$('.access a').live('click', function () {
var href = $(this).attr('href');
goTo(href);
history.pushState(null, null, href);
return false;
});
window.onpopstate = function () {
if (historyCount) {
goTo(document.location);
}
historyCount = historyCount + 1;
};
}
The window load event only happens once. What you will want to do is parse the content into an html fragment, loop through and preload the images, and then append the content.