SoFunction
Updated on 2025-02-28

The use and basics of jQuery callback function (callback)


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/"></script>
    </head>
<style>
body{font-family: "Microsoft Yahei";width: 980px; margin: 0 auto; text-align: center;}
    .box{
        width: 300px;
        height: 300px;
        background: green;
        border: 1px solid #e6e6e6;
        margintop: 50px;
        line-height: 200px;
        position: absolute;
    }
button{
    border: none;
    background: green;   
    width: 100px;
    height: 50px;
    line-height: 50px;
    color: #fff;
    font-size: 16px;
    margin-top: 50px;
    }
</style>
    <body>
<button>Click to start animation</button>
        <div class="box" ></div>
        <script>
            $(document).ready(function(){
              $("button").click(function(){
                var div=$(".box");
                ({height:'200px',opacity:'0.4'},"slow");
                ({width:'200px',opacity:'0.8'},"slow");
                ({height:'100px',opacity:'0.4'},"slow");
                ({width:'100px',opacity:'0.8'},"slow");
                ({right:'100px',opacity:'0.8'},"slow");
                ({bottom:'100px',opacity:'0.8'},"slow");
                ({left:'100px',opacity:'0.8'},"slow");
                ({top:'100px',opacity:'0.8'},"slow",function(){
                    alert("The paragraph is over");
                });
              });
            });
        </script>
        <script>
            $(document).ready(function(){
                $("button").click(function(){
                    var div=$(".box");
                        ({height:'300px',opacity:'0.4'},"slow");
                        ({width:'300px',opacity:'0.8'},"slow");
                        ({height:'100px',opacity:'0.4'},"slow");
                        ({width:'100px',opacity:'0.8'},"slow",function(){
                    alert("The paragraph is over");
                });
                    });
                });
            });
        </script>
    </body>
</html>