首页 > 代码库 > 商品飞入购物车特效
商品飞入购物车特效
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>购物车特效</title> | |
<script src="http://cdn.bootcss.com/jquery/1.8.1/jquery.js"></script> | |
<style type="text/css"> | |
*{ | |
margin:0px; | |
padding:0px; | |
border:0px; | |
} | |
#container{ | |
width:1000px; | |
height:600px; | |
border:1px solid gray; | |
position:relative; | |
padding:10px; | |
} | |
.shangpin{ | |
width:230px; | |
height:auto; | |
border:1px solid aquamarine; | |
text-align: center; | |
float: left; | |
margin:0px 20px 20px 0px; | |
} | |
.shangpin button{ | |
background: lightblue; | |
cursor:pointer; | |
height:20px; | |
width:100px; | |
} | |
.clearflo{ | |
clear:both; | |
} | |
#shopingcar{ | |
width:100px; | |
height:50px; | |
border:1px solid red; | |
position:absolute; | |
top:0px; | |
right:0px; | |
background:gray; | |
color:red; | |
} | |
#shopingcar img{ | |
width:50px; | |
height:50px; | |
} | |
#shopingcar .num{ | |
position:absolute; | |
top:2px; | |
left:15px; | |
} | |
</style> | |
<script type="text/javascript"> | |
$(function(){ | |
var carnum=0; | |
$(".shangpin button").on("click",function(){ | |
var shopcar=$("#shopingcar"); | |
var img=$(this).parents(".shangpin").find("img"); | |
var cloneimg=img.clone(); | |
cloneimg.css({ | |
"width":"230px", | |
"height":"230px", | |
"opacity":"0.5", | |
"position":"absolute", | |
"top":img.offset().top, | |
"left":img.offset().left, | |
"z-index":"1111" | |
}).appendTo($("body")).animate({ | |
"width":"50px", | |
"height":"50px", | |
"top":shopcar.offset().top, | |
"left":shopcar.offset().left | |
},2000,function(){ | |
cloneimg.animate({ | |
"width":"0", | |
"height":"0" | |
},function(){ | |
$("#shopingcar .num").html(++carnum) | |
$(this).detach() | |
}) | |
}) | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<div id="container"> | |
<div class="shangpin"> | |
<img src="http://www.mamicode.com/img/1.jpg" id="img" /> | |
<p class="price"> price:15.55 </p> | |
<button>加入购物车</button> | |
</div> | |
<div class="shangpin"> | |
<img src="http://www.mamicode.com/img/2.jpg" id="img" /> | |
<p class="price">price:</p> | |
<button>加入购物车</button> | |
</div> | |
<div class="shangpin"> | |
<img src="http://www.mamicode.com/img/3.jpg" id="img" /> | |
<p class="price">price:</p> | |
<button>加入购物车</button> | |
</div> | |
<div class="shangpin"> | |
<img src="http://www.mamicode.com/img/4.jpg" id="img" /> | |
<p class="price">price:</p> | |
<button>加入购物车</button> | |
</div> | |
<div class="shangpin"> | |
<img src="http://www.mamicode.com/img/5.jpg" id="img" /> | |
<p class="price">price:</p> | |
<button>加入购物车</button> | |
</div><div class="shangpin"> | |
<img src="http://www.mamicode.com/img/6.jpg" id="img" /> | |
<p class="price">price:</p> | |
<button>加入购物车</button> | |
</div> | |
<div class="clearflo"></div> | |
<div id="shopingcar"> | |
<img src="http://www.mamicode.com/img/car.png" /> | |
<p class="num">0</p> | |
</div> | |
</div> | |
</body> | |
</html> | |
商品飞入购物车特效
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。