我有一个使用 ajax 加载主要内容的网站,我正在使用以下代码在完成afterLoad
后运行一个函数 () .load()
..
jQuery('.main-menu a').click(function(evt){
var href = jQuery(this).attr('href');
var elementClassName = jQuery(this).attr('class');
History.pushState({}, '', href);
jQuery('.content').load(href+ ' #main',afterLoad);
function afterLoad() {
jQuery('.content').fadeIn(750);
if (document.location.pathname == "/works/") {
jQuery(function($){ window.dzsp_init("#port0",{
settings_slideshowTime:3
,settings_mode: "masonry"
,title: ""
,design_item_width: ""
,design_item_height: ""
,design_categories_style: "normal"
,design_categories_pos: "top"
,design_pageContent_pos: "top"
,settings_disableCats: "off"
,settings_lightboxlibrary: "zoombox"
,settings_preloadall: "off"
,audioplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/ap.swf"
,videoplayer_swflocation: "http://sbmdesigns.net/wp-content/plugins/dzs-portfolio/preview.swf"
,disable_itemmeta: "off"
,settings_ajax_loadmoremethod: "button"
,settings_mode_masonry_layout: "masonry"
,design_total_height_full: "off"
,settings_mode_masonry_layout_straightacross_setitemsoncenter: "off"
,design_item_height_same_as_width : "off"})
});
}
}
return false;
});
一切正常,但有时在完成afterLoad
之前运行.load()
。无论如何要延迟afterLoad
以确保一切都在触发之前完成加载。