Home  >  Article  >  Web Front-end  >  How to make a heart-shaped pattern float when clicked by the mouse

How to make a heart-shaped pattern float when clicked by the mouse

php中世界最好的语言
php中世界最好的语言Original
2018-06-08 14:10:102085browse

This time I will show you how to make a heart-shaped pattern float when clicked by the mouse. What are the precautions for how to make a heart-shaped pattern float when clicked by the mouse. The following is a practical case, let's take a look.

The example in this article describes how jQuery can achieve the cool effect of heart-shaped floating at the mouse click. Share it with everyone for your reference, the details are as follows:

Click the mouse once, a love ❤ will be displayed above the mouse, and it will slowly disappear upwards, as shown below:

Isn’t it cool? Just 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:

Using vue components in practical cases

angular print page designation function

The above is the detailed content of How to make a heart-shaped pattern float when clicked by the mouse. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn