jQuery Animation How to - Show element with fade in








Question

We would like to know how to show element with fade in.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
div {<!-- ww  w  .  ja v  a 2s.  c o  m-->
  width: 100px;
  height: 100px;
  background-color: Red;
  display: none;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $("div").css({
        "opacity":"0",
        "display":"block",
    }).show().animate({opacity:1});
});
</script>
</head>
<body>
  <div>Hello</div>
</body>
</html>

The code above is rendered as follows: