Home >Web Front-end >JS Tutorial >Implementing the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in_jquery

Implementing the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in_jquery

WBOY
WBOYOriginal
2016-05-16 15:06:461890browse

Let me show you the renderings first:


In shopping websites, the function of adding to the shopping cart is a necessary function. On some websites, when the user clicks the add to the shopping cart button, the product will appear to be added to the shopping cart in a parabolic animation from the click. This function can be seen It looks very cool and improves the user experience to a certain extent. The following introduces the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in.

It is very convenient to use the jquery.fly plug-in to realize the function of adding parabolic animation to the shopping cart

1. Plug-in download

Plug-in official:https://github.com/amibug/fly

2. Load the jQuery library file and jquery.fly.min.js plug-in

<script src="jquery.js"></script> 
<script src="jquery.fly.min.js"></script>

3. Add to Cart Animation Fly-In Effect Example

The effect we want to achieve is: when the "Add to Shopping Cart" button is clicked, the product image will turn into a shrinking ball, starting from the button, flying out in a parabola to the right to the shopping center on the right. in the car. Before flying out, we need to get the picture of the current product, and then call the fly plug-in. The subsequent parabolic trajectories are completed by the fly plug-in. We only need to define the left side of the starting point and end point and the animation before destruction after the end.

<div class="container">
<div class="demo clearfix">
<div class="per">
<img src="images/1.jpg"    style="max-width:90%"  style="max-width:90%" alt="Implementing the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in_jquery"/>
<div class="title">aaa</div>
<a href="javascript:void(0);" class="button orange addcart">加入购物车</a>
</div>
<div class="per">
<img src="images/2.jpg"    style="max-width:90%"  style="max-width:90%" alt="Implementing the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in_jquery"/>
<div class="title">bbb</div>
<a href="javascript:void(0);" class="button orange addcart">加入购物车</a>
</div>
</div>
</div>
<div class="cart-sidebar">
<div class="cart">
<i id="icon-cart"></i>
<span>购物车</span>
</div>
</div>
<div id="tip">成功加入购物车!</div>
<script>
$(function() { 
var offset = $("#icon-cart").offset(); 
$(".addcart").click(function(event) { 
var img = $(this).parent().children('img').attr('src'); //获取当前点击图片链接 
var flyer = $('<img  class="flyer-img" src="' + img + '" alt="Implementing the parabolic animation effect of adding to the shopping cart based on the jquery fly plug-in_jquery" >'); //抛物体对象 
flyer.fly({ 
start: { 
left: event.pageX,//抛物体起点横坐标 
top: event.pageY //抛物体起点纵坐标 
}, 
end: { 
left: offset.left + 10,//抛物体终点横坐标 
top: offset.top + 10, //抛物体终点纵坐标 
}, 
onEnd: function() { 
$("#tip").show().animate({width: '200px'},300).fadeOut(500);////成功加入购物车动画效果 
this.destory(); //销毁抛物体 
} 
}); 
}); 
});
<script>

Remarks

Below IE10 you need to add the following js:

<script src="requestAnimationFrame.js"></script>

The above is for the jquery fly plug-in to implement the parabolic animation effect of adding to the shopping cart. I hope it will be helpful to everyone!

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