Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery fadeIn leaves opacity at 0

Tags:

jquery

fadein

I have this weird behavior with .fadeIn()

If I write

$('#MyDiv').show();

The div shows just fine.

However, if I write

$('#MyDiv').fadeIn(400);

The div shows but with opacity 0!

The line before is:

$('#MyDiv').hide()
    .html(TheHTML)
    .css('top', 0);

UPDATE: if I write $('#MyDiv').show(400);

The div also stays at opacity 0.

like image 682
frenchie Avatar asked Jun 01 '12 06:06

frenchie


3 Answers

Some CSS is overriding your div when it is hidden..Better add the opacity style to your div as 1.

Else do,

$('#MyDiv').css('opacity','1');

After your fadeIn call...

like image 70
Kabilan S Avatar answered Nov 15 '22 07:11

Kabilan S


Try jQuery .fadeTo function.

.fadeTo( duration, opacity [, callback] )  
.fadeTo( duration, opacity [, easing] [, callback] )  

Sample:

$('#book').fadeTo('slow', 0.5, function() {
  // Animation complete.
});
like image 33
Tooraj Jam Avatar answered Nov 15 '22 06:11

Tooraj Jam


The following will make it visible as you want

$('#MyDiv').animate({
  opacity: 1
},400);

You can try following:

$('#MyDiv').fadeIn(400, function(){
    $(this).css('opacity', 1)
});

DEMO

But I think your should also work just fine. See here

like image 21
thecodeparadox Avatar answered Nov 15 '22 06:11

thecodeparadox