This time I will bring you jQuery to achieve the heart-shaped floating effect at the mouse click (with code). What are the things to note about jQuery to achieve the heart-shaped floating effect at the mouse click. The following is a practical case, one Get up and 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>
Detailed explanation of the overall architecture analysis and use of jquery
Detailed explanation of jQuery's method of judging the type and size of uploaded images
The above is the detailed content of jQuery achieves heart-shaped floating effect on mouse click (with code). For more information, please follow other related articles on the PHP Chinese website!