Search code examples
javascriptcsshtmlfade

Make a div fade away nicely after a given amount of time


What is the best way to make a <div> fade away after a given amount of time (without using some of the JavaScript libraries available).

I'm looking for a very lightweight solution not requiring a huge JavaScript library to be sent to the browser.


Solution

  • Not sure why you'd be so against using something like jQuery, which would make accomplishing this effect all but trivial, but essentially, you need to wrap a series of changes to the -moz-opacity, opacity, and filter:alpha CSS rules in a setTimeout().

    Or, use jQuery, and wrap a fadeOut() call in setTimeout. Your choice.