I'm trying to load #content of a url via AJAX using jQuery within #primary. It loads but doesn't fadeIn. What am I doing wrong?
$('.menu a').live('click', function(event) { var link = $(this).attr('href'); $('#content').fadeOut('slow', function(){ $('#primary').load(link+' #content', function(){ $('#content').fadeIn('slow'); }); }); return false; });
Many thanks for your help.
The jQuery fadeIn() method is used to fade in a hidden element. Syntax: $(selector).fadeIn(speed,callback); The optional speed parameter specifies the duration of the effect.
The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.
onload=fadeIn, is used to call the fadeIn() function automatically. The fadeIn() function calls an in-built method setInterval(), which takes two parameters, one is function reference(show() in this case), and time interval(to take reference of function after selected interval).
Actually I was able to do it by applying the effect to the wrapper div instead...
$('#primary').fadeOut('slow', function(){ $('#primary').load(link+' #content', function(){ $('#primary').fadeIn('slow'); }); });
Just this:
$('.element').load('file.html',function(){}).hide().fadeIn();
Or to add this behaviour as default in the load() function:
$.fn.load_=$.fn.load; $.fn.load=function(){ return $.fn.load_.apply(this,arguments).hide().fadeIn(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With