3
I am trying to send a message to the user using jQuery and hide it automatically after a few seconds. This procedure occurs perfectly unless the event occurs in less time than the time to hide the message, causing the message not to arrive synchronized with the event. To perform a test click multiple times on the link to follow the result.
Follow the example:
$('#id').click(function(){
$("#msg").html('<div class="alert alert-success">ALERTA</div>').hide().fadeIn();
$("#msg").delay(5000).fadeOut();
});
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://getbootstrap.com/dist/css/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href="#" id="id" class="btn">alerta</a>
<div id="msg"></div>
NOTE: Any other solution to solve this problem is welcome.
Forehead joining a
.stop()
thus:$("#msg").html('<div class="alert alert-success">ALERTA</div>').hide().stop().fadeIn();
– Sergio
I can consider the answer as valid, but it did not fully meet the expected, because after multiple touches ended up leaving the event sync.
– adrianosymphony