문제

I want to replace a div's content and then make it visible

$("#btn").click(function () {
$('#div01').load('about.php');
$("#div01").slideDown("slow");
});

But the div becomes visible before the content is changed, so user can see the previous content - which is not the idea.

도움이 되었습니까?

해결책

The second parameter of the load() function can be used as a callback function. So the slideDown() only occurs when the load is complete:

$("#btn").click(function () {
    $('#div01').load('about.php', function(){
        $("#div01").slideDown("slow");
    });
});

다른 팁

Try this:

$("#btn").click(function () {
    $('#div01').load('about.php',function(){
        setTimeout(function(){$("#div01").slideDown("slow")},100);
    });
});

.load() is an ajax function so try to get it after ajax completes with jQuery.ajaxComplete():

$("#btn").click(function () {
     $('#div01').load('about.php');
});

$.ajaxComplete(function(){
   $("#div01").slideDown("slow");
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top