Skip to content Skip to sidebar Skip to footer

Jquery - How Can I Add A Fade In/out Effect To My Function Instead Of Just Setting Visibility Hidden/visible

Can you tell me how can I add a nice fade effect for smoother animation to my function instead of setting visibility hidden / visible at an regular interval. I am not looking for a

Solution 1:

use this:

if (!$(elem).is(':visible')) {
    $(elem).fadeIn( "slow");
} else {
    $(elem).fadeOut( "slow");
}

Or use the toggle function of jquery:

$(elem).toggle("slow");

For fadeIn function read here.

For fadeOut function read here.

For toggle function read here.

Solution 2:

Try below jQuery code

setBlinkingInterval: function(elem, event) {
    if (intervalIdForBlinking != 0) 
        window.clearInterval(intervalIdForBlinking);

    $(elem).show();
    intervalIdForBlinking = setInterval(function() {
       if (eventsObj.eventIsFinished(event)) {
          timer.setClosedStatus(elem, event);
       }
       else {
          if ($(elem).is(':visible')) 
               $(elem).fadeOut(3000);
          else
               $(elem).fadeIn(3000);
       }
   }, 500);
} 

FadeIn and fadeOut examples

fadeIn API Details

fadeOut API Details

Solution 3:

They are two methods to do this first is to use Jquery toggle() functionality.

elem.toggle("slow");

It will automatically toggle to other form.

Or you can use Jquery fadeIn() and fadeOut().

if (!$(elem).is(':visible')) {
    $(elem).fadeIn( "slow");
} else {
    $(elem).fadeOut( "slow");
}

Post a Comment for "Jquery - How Can I Add A Fade In/out Effect To My Function Instead Of Just Setting Visibility Hidden/visible"