开发者

How to fade in/out an HTML DIV container using JavaScript?

开发者 https://www.devze.com 2023-01-20 04:57 出处:网络
I have an DIV cont开发者_Python百科ainer with an id=\"myDiv\" attribute+value. I\'d like to fade this in/out smoothly.

I have an DIV cont开发者_Python百科ainer with an id="myDiv" attribute+value. I'd like to fade this in/out smoothly.

Would I have to create some sort of run loop with an timer and then modify the opacity value of the DIV?

Is jQuery perfect for this kind of stuff?


The jQuery has fadeIn and fadeOut methods to create the fading effect. You can for example use them like this on your div:

$('#myDiv').fadeOut('slow');

Or you can also use the animate method and specify the opacity option to it to create the fading effect.

Not to forget about the fadeTo method too :)


jQuery is perfect.

$('#myDiv').fadeOut();

http://api.jquery.com/fadeOut/

http://api.jquery.com/fadeIn/

0

精彩评论

暂无评论...
验证码 换一张
取 消