Share on Google+Share on Google+

Fading elements in and out example

This page discusses - Fading elements in and out example

Fading elements in and out example


Fading elements in and out example

For fading effect jQuery has following three methods :

.fadeIn( )

This method fade the matched elements to opaque.

Example :

Following code animates hidden divs to fade in :


.fadeTo( )

This method can be used for adjusting  the opacity of the matched elements.

Example :

Following code change the opacity of the image :

$('#clickmeDiv').click(function() {
  $('#image').fadeTo('slow', 0.5, function() {
  // Animation complete.

.fadeOut( )

This method hide the marched element and set their visibility to transparent.

Example :

In this Example, a list is given , if we hover on first two element, "<<<" is appended on it, to show mouse pointing. If we hover on last two elements ,"<<<" is appended on it & it will fade out/in to show mouse pointing.

<!DOCTYPE html>
  ul { margin-left:20px; color:blue; }
  li { cursor:default; }
  span { color:red; }
  <script src="jquery-1.4.2.js"></script>

<h3><font color="red">Hover on any element to see effect</font></h3>
    <li class='fade'>Patties</li>
	<li class='fade'>Noodles</li>
      function () {
        $(this).append($("<span><<< </span>"));
      function () {
 //li with fade class


Output :

When we hover on second element of the list :

When we hover on last two elements ., it will fade in/out + append string "<<<" :

Download Source Code

Click here to see demo

Learn from experts! Attend jQuery Training classes.


Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Fading elements in and out example  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image