HTML Element Style How to - Fade image out after loading








Question

We would like to know how to fade image out after loading.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.4.js'></script>
<script type='text/javascript'>
$(function(){<!--from ww w . j  a v  a 2s .  c  o  m-->
    $(window).load(function () {
        // Page is fully loaded .. time to fade out your div with a timer ..
        $('#overlay').fadeOut(5000);
    });
});
</script>
</head>
<body>
  <div id="overlay">
    <img
      src="http://www.java2s.com/style/download.png"
      alt="Loading" />Loading...
  </div>
</body>
</html>

The code above is rendered as follows: