Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-displaying after fadeOut

Tags:

jquery

Please can I affirm that I am doing this correctly:

I have a message that I wish to fadeOut after it has been displayed.

The jQuery fadeOut sets display: none once the opacity is zero.

Thus when I want to display that same message again by setting visibility: visible the message won't display because display: none is still set.

So this is what I did:

        $("#message6").fadeOut(600, function(){
            $("#message6").css("display","");
            $("#message6").css("visibility","hidden");              
        });

This works just fine. It doesn't seem very elegant.

Am I missing something here? Is there a neat way of doing this?

like image 767
codepuppy Avatar asked Nov 05 '12 08:11

codepuppy


People also ask

What is fadeOut effect?

The Fade In/Fade Out behavior lets you dissolve into and out of any object by ramping the opacity of the object from 0 percent to 100 percent at the start, and then back to 0 percent at the end. You can eliminate the fade-in or fade-out effect by setting the duration of the Fade In Time or Fade Out Time to 0 frames.

What is the difference between fadein and fade in and out?

Answer: Fade in: When darkness slowly turns into a image then that's called Fade in. This is normally used when film begins. ... Fade out: When an image slowly turns into darkness then that's called Fade out.

How to stop fadeOut jQuery?

stop(). animate({opacity:'100'}) combo is what allows any fadIn/fadeOut to restart based on your trigger. Works great.

How does jQuery fadeOut work?

fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.


2 Answers

Why don't you do:

$("#message6").fadeOut(600);

And to show your message again:

$("#message6").show();
like image 106
iappwebdev Avatar answered Nov 12 '22 06:11

iappwebdev


Why not something like this

$(document).ready(function() {
        $('#myLabel').fadeOut(1000, function() {
            $(this).html(""); //reset the label after fadeout
        });
    });​

Sample

like image 44
Priyank Patel Avatar answered Nov 12 '22 08:11

Priyank Patel