WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

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

Topic: JavaScript / jQueryPrev|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 src="https://code.jquery.com/jquery-1.12.4.min.js"></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 drop us a line.