Ajaxed div隐藏并显示隐藏div加载后隐藏

时间:2011-02-15 18:04:06

标签: ajax html hide show

我有这个问题。我正在开发一个jquery ajaxed网站。我有主要内容div在中间和顶部导航。我需要AJAX的内容,因为我有flash背景,因此flash视频不会在每次加载页面后从头开始。我能够做到这一点的唯一方法是使用这种代码:

$(document).ready(function(){


$.ajaxSetup ({  
         cache: false  
         }); 

//For loading
     var ajax_load = "<img src='img/load.gif' alt='loading...' /><p>";  

 //  Var
    var loadPage1 = "page1.html";

//  Load page
    $("#page1").click(function(){
            $("#content").hide(2000);
            $("#content").html(ajax_load).load(loadPage1);
            $("#content").show(2000);
});

获取div的所有其他方法都不起作用,因为在ajaxed div(内容)中使用插件等工作存在问题。

所以... everythig工作正常 - 但是,div从page1.html加载它的内容并显示它,并且只有在这之后才隐藏它并显示它。所以它加载页面然后做我想要的效果。

我是否需要按照正确的jquery方式对此进行排队?我试过延迟,停止等等。但似乎无法解决这个问题。它非常简单。

感谢。

2 个答案:

答案 0 :(得分:2)

在加载回调处理程序中显示该元素。 即:

$("#page1").click(function(){             
    $("#content").hide();             
    $("#content").html(ajax_load).load(loadPage1, function(){
        $("#content").show(2000)
    });
}); 

答案 1 :(得分:0)

.load()接受2个参数,URI和加载后触发的回调。 API可在此处找到:http://api.jquery.com/load/

function() {
    $("#content").hide(2000);
    $("#content").html(ajax_load).load(loadPage1, function() {
        $("#content").show(2000);
    });
}