Home > Article > Web Front-end > jQuery implements mouse click suspension effects
This time I will bring you jQuery to implement mouse click suspension effects. What are the precautions for jQuery to implement mouse click suspension effects? The following is a practical case, let’s take a look.
Click the mouse once, and a heart ❤ will be displayed above the mouse, and it will slowly disappear upwards, as shown below:
Isn’t it cool? , post the code directly:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>测试</title> <script src="http://libs.baidu.com/jquery/2.0.0/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('你点击了一下');//双数显示这个 }else{ var $i=$('<b></b>').text('❤');//单数显示这个 } n++; var x=e.pageX,y=e.pageY;//获取鼠标点击的位置坐标 $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(); });//设置动画 }); }); </script> </head> <body> <p id="test"> </p> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of the use of mapState and mapGetters in vuex
Detailed explanation of the steps to use vuex (with code)
The above is the detailed content of jQuery implements mouse click suspension effects. For more information, please follow other related articles on the PHP Chinese website!