I'm displaying a message (#final_msg) after the user submits the form. What I want to do is that, after 15 seconds, the message (#final_msg) should fade out, clearing away [or fading out] the text in the input elements as well. Is it possible to do this?
else {
//create post data
var postData = {
"name" : $("#name").val(),
"email" : $("#email").val(),
"msg" : $("#msg").val(),
"origin" : $("#origin").val()
};
//make the call
$.ajax({
type: "POST",
url: "test.php",
data: postData, //send it along with your call
success: function(response){
$('#final_msg').fadeIn();
}
});
}
The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector). fadeOut(speed,callback);
If it's not an animation, use setTimeout() directly, like this: $("#myElem"). show(); setTimeout(function() { $("#myElem"). hide(); }, 5000);
jQuery Effect fadeOut() Method The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeIn() method.
jQuery has 2 fading methods which are . fadeIn() and . fadeOut(). The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent.
If you're on jQuery 1.4, you can use the delay
function:
$('#final_msg').fadeIn().delay(10000).fadeOut();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With