jQuery achieves cool effects at mouse clicks

Click the mouse to display a heart ❤ above the mouse, and it has the effect of slowly disappearing upwards, as shown below

 


Isn't it cool, paste the code directly:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Test</title>
    <script type="text/javascript" src="./jquery.min.js"></script>
    <style type="text/css">
        *{
            margin: 0px;
            padding: 0px;
        }
    </style>
    <script type="text/javascript">
        $(function(){
            var height=$(window).width();
            $('#test').css({
                'height':height,
            });
            var n=1;
            $('#test').click(function(e){
                if(n%2==0){
                    var $i=$('<b></b>').text('You clicked');//Dual numbers show this
                }else{
                    var $i=$('<b></b>').text('❤666');//Display this in singular
                }
                n++;
                var x=e.pageX,y=e.pageY;//Get the position coordinates of the mouse click
                $i.css({
                    "z-index": 9999,
                    "top": y - 20,
                    "left": x,
                    "position": "absolute",
                    "color": 'red',
                    "font-size": 14,
                });
                $("body").append($i);
                $i.animate({
                    "top": y - 180,
                    "opacity": 0
                }, 1500, function() {
                    $i.remove();
                });//Set animation
            });
        });
    </script>
</head>
<body>
<div id="test">

</div>
</body>
</html>

 

It mainly uses the animate special effect of css, which I will summarize in a later article

 

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326289960&siteId=291194637