Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .load() with fadeIn effect

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.

like image 789
Gab Avatar asked Feb 18 '12 00:02

Gab


People also ask

What is the syntax of jQuery fadeIn () method?

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.

Which of the following method is used to toggle between the fadeIn () method and fadeOut () method?

The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.

How do you make a fade effect in Javascript?

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).


2 Answers

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');     }); }); 
like image 185
Gab Avatar answered Sep 22 '22 14:09

Gab


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(); } 
like image 41
Brynner Ferreira Avatar answered Sep 23 '22 14:09

Brynner Ferreira