Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery can I display the result then have it fade away?

Tags:

jquery

Is there a way I can display the result and then have it fade away after about 10 seconds or something using JQuery?

Here is the code.

function stop(){
    $.ajax({
        type: "GET",
        url: "http://update.php",
        data: "do=getSTOP",
        cache: false,
        async: false,
        success: function(result) {
            $("#rate").html(result);
        },
        error: function(result) {
            alert("some error occured, please try again later");
        }
    });

    return false;
}

$(document).ready(function() {

    $('.rating li a, .srating li a').click(stop);

});
like image 513
jsnag Avatar asked Aug 05 '10 23:08

jsnag


People also ask

How do I fadeOut text in jQuery?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector). fadeOut(speed,callback);

Which jQuery function can you use to make an element fade until it disappears?

jQuery Effect fadeOut() Method The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect).

What is FadeIn and fadeOut in jQuery?

The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent. Note – jQuery does the fading by changing the opacity of the element.

What is the difference between fadeOut and hide in jQuery?

Main difference between FadeIn, FadeOut vs hide, Show is When you use FadeIn and fadeout Its remove line Slowly Like Opacity will 100 to 0 in a few mili-second but On other hand hide, Show will remove the line immediately Without wasting any mili-second.


1 Answers

You can use .delay() for this, like this:

$("#rate").html(result).delay(10000).fadeOut();

This does a .delay() for 10 seconds then performs a .fadeOut() animation, no reason to make it any more complicated I think :)

like image 111
Nick Craver Avatar answered Nov 25 '22 01:11

Nick Craver