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

<!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> 







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