» » Use jQuery to achieve ADD TO CART flying into animation

 

Use jQuery to achieve ADD TO CART flying into animation

Author: bamboo06 on 4-05-2015, 02:59, views: 9406

11
When you browse the electricity supplier shopping site favorite products, you can click on the page in the "Add to Cart" button to add the items to the shopping cart. This article describes the aid of a jQuery-based animation plugin, click on the Add to Cart button when you realize the goods will fly into the right side of the cart in effect.


HTML
First load jQuery library files and jquery.fly.min.js plugins.
<script src="jquery.js"></script> 
<script src="jquery.fly.min.js"></script> 

Then, the product information html good structural arrangement, in this case, we use four commodities arranged side by side, each box of merchandise including product images, price, name, and Add to Cart buttons and other information.
	<div class="demo">
		<div class="box">
			<img src="images/lg.jpg" width="180" height="180">
			<h4>$<span>600.00</span></h4>
			<p>LG 49LF5400-CA 49-inch</p>
			<a href="#" class="button orange addcar">Add to cart</a>
		</div>
		<div class="box">
			<img src="images/hs.jpg" width="180" height="180">
			<h4>$<span>660.00</span></h4>
			<p>Hisense LED50T1A</p>
			<a href="#" class="button orange addcar">Add to cart</a>
		</div>
		<div class="box">
			<img src="images/cw.jpg" width="180" height="180">
			<h4>$<span>¥700.00</span></h4>
			<p>Skyworth 50E8EUS</p>
			<a href="#" class="button orange addcar">Add to cart</a>
		</div>
		<div class="box">
			<img src="images/ls.jpg" width="180" height="180">
			<h4>$<span>1000.00</span></h4>
			<p>Letv X60S 4 cores</p>
			<a href="#" class="button orange addcar">Add to cart</a>
		</div>
	</div>

Then, we also need the right side of the page plus cart and prompt information.
	<div class="m-sidebar">
		<div class="cart">
			<i id="end"></i>
			<span>Cart</span>
		</div>
	</div>
	<div id="msg">Added to the shopping cart!</div>


CSS
We use CSS first commodity arrangement landscaping, and then set the right side of cart-style details, please read the code:
.box{float:left; width:198px; height:320px; margin-left:5px; border:1px solid #e0e0e0; text-align:center} 
.box p{line-height:20px; padding:4px 4px 10px 4px; text-align:left} 
.box:hover{border:1px solid #f90} 
.box h4{line-height:32px; font-size:14px; color:#f30;font-weight:500} 
.box h4 span{font-size:20px} 
.u-flyer{display: block;width: 50px;height: 50px;border-radius: 50px;position: fixed;z-index: 9999;} 
 
.m-sidebar{position: fixed;top: 0;right: 0;background: #000;z-index: 2000;width: 35px;height: 100%;font-size: 12px;color: #fff;} 
.cart{color: #fff;text-align:center;line-height: 20px;padding: 200px 0 0 0px;} 
.cart span{display:block;width:20px;margin:0 auto;} 
.cart i{width:35px;height:35px;display:block; background:url(car.png) no-repeat;} 
#msg{position:fixed; top:300px; right:35px; z-index:10000; width:1px; height:52px; line-height:52px; font-size:20px; text-align:center; color:#fff; background:#360; display:none} 


jQuery
We want to achieve the effect is that when the user clicks on "Add to Cart" button, the current commodity picture will become a miniature ball to the button as a starting point, to the right in the form of a parabolic flying, finally falling into the right page side of the shopping cart, and prompts a successful operation. Before flying out, we have to get the current picture of goods, then call the fly plugin, after the fly parabolic trajectory is done by plug-ins, we only need to define the start and end points and other parameters.
<script>
$(function() {
	var offset = $("#end").offset();
	$(".addcar").click(function(event){
		var addcar = $(this);
		var img = addcar.parent().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+10,
				top: offset.top+10,
				width: 0,
				height: 0
			},
			onEnd: function(){
				$("#msg").show().animate({width: '250px'}, 200).fadeOut(1000);
				addcar.css("cursor","default").removeClass('orange').unbind('click');
				this.destory();
			}
		});
	});
  
});
</script>

Copy the above code, save and run to see the effect, Fly widget project official website address is: https: //github.com/amibug/fly, it is worth mentioning that, IE10 less need to add the following js:
<script src="requestAnimationFrame.js"></script> 

Category: Javascript

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
31 December 2015 23:58

vishal patel

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
awesome work......

<
  • 0 Comments
  • 0 Articles
15 June 2017 05:55

Tara Rodriguez

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This is great now we finally can use jQuery to achieve ADD TO CART flying into animation. My math done is also over, now there is nothing more I want to learn, a lot more about this, keep me posted.

<
  • 0 Comments
  • 0 Articles
9 July 2017 19:46

Rebecca Wilkinson

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This is great, we can now use jQuery to achieve ADD TO CART flying into animation and to video companies denver. This is all I was looking for, great post and the share, hope to read more about this software.

<
  • 0 Comments
  • 0 Articles
17 July 2017 00:20

Gale Snider

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I have tried many diet supplements and cant imagine how much money I have spent over the years. I am guessing thousands of dollars. Until I get these pure diet drops from here, these are the best and the ones that actually works.

<
  • 0 Comments
  • 0 Articles
18 August 2017 22:37

jimini

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I love CSS coding because it give a good look to any website so i would recommend each webmaster to get maximum attention towards this rather than going for Php. We have many best custom essay writing service working quite amazingly well on internet and i believe it is the best thing that i did, i only changed the front look of my all websites.

<
  • 0 Comments
  • 0 Articles
26 October 2017 17:12

GKathlene Eisert

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
test test test test test test test

<a href="http://www.undangancinta.com">undangan pernikahan</a>
undangan pernikahan unik
https://goo.gl/XZ6zpY undangan nikah
<a href="http://bit.ly/2fZoVjU">jual hp asus murah</a>
http://www.undangancinta.com # Undangan Pernikahan
http://www.undangancinta.com # Undangan Pernikahan



碸 ÐŮ

<
  • 0 Comments
  • 0 Articles
15 November 2017 05:09

Kifsha

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
HTML5 has been released now and now it includes different things where animation is the best thing to move, you can add different animation without going to use long and detailed scripts, HTML will help you there. Now we are planning to teach it in ataschool to let students know more about such things, students love to learn HTML as results are attractive and you can see on the spot.

<
  • 0 Comments
  • 0 Articles
12 December 2017 01:33

Escorts Service in Kolkata

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Beauti Queen amazing kolkata escorts agency alwyas ready for you at your doorstep. Beauti Queen provide you high profile independent girl in kolkata, escorts service in kolkata, kolkata escorts. If you are looking for the ultimate encounter in Kolkata then I am your sophisticated young Kolkata escorts that provides upscale companionship for making your night becomes true.
escorts service in kolkata, kolkata escorts, escorts in kolkata, independent escorts in kolkata, female escorts in kolkata

<
  • 0 Comments
  • 0 Articles
29 January 2018 11:20

Independent Escorts in Kolkata

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Renu Das Kolkata Escorts Services has gorgeous females provides Independent Escorts Service in Kolkata call girls at 100% satisfaction with VIP models. Provided Kolkata escorts at our agency are professional in nature and are eager to serve you at your place.
kolkata escorts, escorts in kolkata, escorts service in kolkata, female escorts in kolkata, escorts agency in kolkata, independent escorts in kolkata

<
  • 0 Comments
  • 0 Articles
27 February 2018 02:36

Delhi Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Riya Chaudhary is an Independent Delhi Escort girl, who offers dazzling hot Delhi Escorts Service, incall or outcall services both to complete your dreams in real entertainment. We offers high class Independent Escorts in Delhi at Riya Chaudhary Delhi Escorts service agency for elite peoples in the city to avail ultimate satisfaction. you can spend your beautiful moments.
delhi escorts, independent escorts in delhi, escorts in delhi

Information
Comment on the news site is possible only within (days) days from the date of publication.