我正在尝试使用 pushstate/html5 从另一个 url 加载内容...我尝试加载的内容有一个很大的背景图像,需要时间来加载...
因此,当它动画快速完整图像似乎出现并滑入但随后图像再次重新加载......
我尝试使用
image preloader/
$(document).ready()
他们都破坏了脚本,似乎无法弄清楚如何在这里加入它
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;
};
}