How to stop firing event until an effect is finished in jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the jQuery callback function

You can utilize the jQuery callback function mechanism to stop events from firing until an effect is completely finished, such as doing something after slide animation or fade out transition is fully completed and so on. Check out the following example.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <title>jQuery Fire Events after an Effect is Over</title>
  • <style type="text/css">
  •     .box{
  •         height: 300px;
  •         display: none;        
  •         background: yellowgreen;
  •     }
  • </style>
  • <script type="text/javascript" src=""></script>
  • <script type="text/javascript">
  • $(document).ready(function(){
  •     $(".box").slideDown(3000, function(){
  •         $(".hint").text("Sliding is completed, now fading out.");
  •         $(this).fadeOut(3000, function(){
  •             $(".hint").text("Fading out completed.");
  •         });
  •     });
  • });
  • </script>
  • </head>
  • <body>
  •     <div class="box"></div>
  •     <p class="hint"></p>
  • </body>
  • </html>

Related FAQ

Here are some more FAQ related to this topic:


Your Feedback:


We would love to hear from you! Please say something.