On this post I will share an amazing Add to Cart jquery animation which use by Prestashop.
For an e-commerce website, it can mean a better shopping experience for customers where they can easy to use, beautiful animation which make the site more interesting, so they can concentrate more on the products which may result in better sales.
Ok, Now I will let you know how the basic of the source.
1. We make a Html file with code below
<table cellpadding="0" cellspacing="0">
<tr> <td width="400px"> <div> <div class="image"><img src="1.jpg" /></div> <div><a class="addCart">Add to Cart</a></div> </div> <div> <div class="image"><img src="1.jpg" /></div> <div><a class="addCart">Add to Cart</a></div> </div> </td> <td width="100px" valign="top"> <div id="shoppingCart"> <h3>Shopping Cart</h3> </div> </td> </tr> </table>
2. Include the javascript code below your html code
<script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){
$(".addCart").click(function(){ var imgsrc = $(this).parent().parent().children(".image").children().attr('src'); var imgpos = $(this).parent().parent().children(".image").children().position(); var imgsrcstyle = "position:absolute;opacity:0.8;display:none;left:"+imgpos.left+"px;top:"+imgpos.top+"px;z-index:99999;"; var this_parent = $(this).parent(); // Ajax request $.ajax({ type: "POST", url: "update.php", data: ({id:'2'}), dataType: "json", cache: false, success: function(result){ if(result['status'] == 'true'){ // make clone image this_parent.append('<img src="'+imgsrc+'" style="'+imgsrcstyle+'" class="cloned" />'); // call animate fly fly(result); } else { alert('Failed add product to cart'); } } }); }); function fly(result){ var box = $('#shoppingCart').position(); $(".cloned").show().animate({ "opacity": 0.2,"top":(box.top + 20),"left":(box.left + 20),"width":10},1500,function(){ $(this).remove(); // update action alert('yay success!'); }); } }); </script>
For the complete source you can download here.
Hope it can help you guys.
Best regard,
Bayu Prawira