Jquery to fade in .after()?
Asked Answered
N

3

8

Simple really but cannot get it to work, here is my script...

$('body').after('<div id="lightBox" style="height: ' + htmlHeight + 'px;"></div>');

How can I get it to fade in rather than just pop up? putting fadeIn() after or before .after() doesn't work?

Noella answered 8/10, 2011 at 23:28 Comment(0)
S
4
$('body').after('<div id="lightBox" style="height: ' + htmlHeight + 'px; display:none;"></div>');
$('#lightBox').fadeIn();
Superphysical answered 8/10, 2011 at 23:30 Comment(0)
D
3
$('body').after('<div id="lightBox" style="height: ' + htmlHeight + 'px;"></div>');  
$("#lightBox").hide().fadeIn();

It hides it and then fades in

Disadvantage answered 8/10, 2011 at 23:31 Comment(1)
Works perfectly, think I was overcomplicating things :pNoella
R
2

Short way:

$('body').after($('<div id="lightBox" style="height: ' + htmlHeight + 'px;"></div>').hide().fadeIn());
Racon answered 17/2, 2016 at 15:10 Comment(1)
This would be a better answer if it included an explanation along with the code.Featly

© 2022 - 2024 — McMap. All rights reserved.