jQuery - overwrite delay() action?
I have this code for an error message that overlaps the page. I just added the click listener - I want it to skip the delay and close right away if it's clicked. However, nothing happens. If I use .hide() in the click listener, it works. But I want to transition it out smooth开发者_如何学Goly.
Any ideas?
// Flash messages effect
$("#FlashMessage").slideDown('250').delay(3000).slideUp('250');
// Hide flash message when clicked
$("#FlashMessage").click(function(){
$("#FlashMessage").slideUp('250');
});
If #FlashMessage
is an actual Flash Object, it might be grabbing input and not issuing the event as expected.
I might be wrong though, but a possible solution might be to use .focus()
instead of .click()`
Try having a image not a flash, and test with that, if it works. I'm right and the flash is denying the event.
jquery.delay is not possible to skip. Use js timeout methods instead
$("#FlashMessage").slideDown('250');
window.setTimeout( function(){ $("#FlashMessage").slideUp('250'); },3000);
// Hide flash message when clicked
$("#FlashMessage").click(function(){
$("#FlashMessage").slideUp('250');
});
http://www.w3schools.com/js/js_timing.asp
精彩评论