Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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. Let's take a look at an example to see how it works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Fire Events after an Effect is Over</title>
<style>
    .box{
        height: 300px;
        display: none;        
        background: yellowgreen;
    }
</style>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to check if an element exists in jQuery... >>
<< How to remove first character from a string in jQu...