×

实现点击爱心飘动起来动画效果

作者:andy0012019.01.28来源:Web前端之家浏览:14988评论:0
关键词:动画

实现点击爱心飘动起来动画效果,一起来学习下吧。

timg.png

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">

  <title></title>
  <style>
    html,body{
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    .demos{
      width: 80px;
      height: 80px;
      position: absolute;
      bottom: 100px;
      left: 50px;
    }
    .demo  {
      width: 80px;
      height: 80px;
      position: absolute;
      bottom: 0;
      left: 0;
    }
    .demoImg{
      font-size: 16px;
      width: 80px;
      height: 80px;
      position: absolute;
      bottom: 0;
      left: 0;
    }

    .endorse {
      width: 80px;
      height: 80px;
      border: 0;
      background: red;
      color: #fff;
      position: absolute;
      bottom: 0;
      left: 0;
      font-size: 16px
    }

  </style>
</head>
<body>
<div class="demos">
  <div class="demo">
    <img class="demoImg" src="/demo/xin/icon_float_1.png" style="bottom: 0.00487377rem; opacity: 0.998375; left: 0.15921px;"   >
  </div>

  <div id="endorse"  class="endorse">变化</div>

</div>

<script src="/demo/js/jq.js"></script>

<script>

  $(function () {
    $("#endorse").click(function(){

      var x = 50;

      var y = 200;
      /* 生成随机数 */
      var num = Math.floor(Math.random() * 4 + 1);
      var index=$('.demo').children('img').length;

      var rand = parseInt(Math.random() * (x - y + 1) + y);
      console.log(rand)

      $(".demo").append("<img src=''>");

      $('img:eq(' + index + ')').attr('src','/demo/xin/icon_float_'+num+'.png')
      console.log(123)
      $("img").animate({
        bottom:"300px",
        opacity:"0",
        left: rand
      },3000,function(){
        $(this).remove();
      })
    })
  })

</script>
</body>
</html>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/xin352385209385.html

网友评论文明上网理性发言 已有0人参与

发表评论: