문제

I am using the .load function to load in another page using jQuery.

Here is my code:

$('#page1').click(function(){                           
  $("#content").load("page1.html");
});

It's working great, but I would like to fade in the new page. Is there anyway I can combine the load and fadeIn function? I attempted it, but it's not working.

Here is my attempt:

$('#page1').click(function(){                           
  $("#content").load("page1.html").fadeIn("normal");
});

How can I combine the .load and .fadeIn function?

도움이 되었습니까?

해결책

The call to load will use AJAX and will be run asynchronously. You'll want to fade in right after the call is terminated. You can achieve that by passing a callback to load. Your code will look like this:

$('#content').load("page1.html", {}, function() { $(this).fadeIn("normal"); }));

See documentation on jQuery's .load() for more information.

다른 팁

Hide #content before the load, and fade in the entire div when load is complete. I'd guess load acceps a callback function...?

$('#content').hide();
$('#content').load('page1.html', function() { $('#content').fadeIn('normal'); });

EDIT do what miguel said, anyway =)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top