最近开发一个平台,需要购物车,仿照网上一些素材制作了一个飞入购物车的特效。
使用了以下脚本:
1.jquery.min.js
2.jquery.fly.min.js
物品列表HTML代码:1
2
3
4
5
6
7
8<ul class="goodslist">
<li>
<img src="url" />
<div class="inner">
<a class="addcar" herf="javascript:void(0)">加入购物车</a>
</div>
</li>
</ul>
购物车代码:1
2
3
4
5
6<div class="car">
<a herf="#">
<i id="end"></i>
购物车
</a>
</div>
调用函数:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20$(funciton(){
var offset=$("#end").offset();
$(".addcar").click(function(event){
var addcar=$(this);
var img=addcar.parents().find('img').attr('src');
var flyer=$('<img class="u-flyer" src="'+img+'">');
flyer.fly({
start:{
left:event.pageX,
top:event.pageY
},
end:{
left:offset.left,
top:offset.top,
width:0,
height:0
}
});
});
});
飞入购物车图片样式1
2
3
4
5
6
7
8.u-flyer{
display:block;
width:50px;
height:50px;
border-radius: 50px;
position: fixed;
z-index: 9999;
}