Over a million developers have joined DZone.

Animate from One Element to Another (jQuery Plugin)

DZone's Guide to

Animate from One Element to Another (jQuery Plugin)

· Web Dev Zone
Free Resource

Try RAD Studio for FREE!  It’s the fastest way to develop cross-platform Native Apps with flexible Cloud services and broad IoT connectivity. Start Your Trial Today!

Have you even tried clicking an “Add to cart”-button and not understood what happened? I have. Although I understand the idea of adding a product to the cart, and then letting the user continue browsing from where he is, I still get stumped when “nothing happens” when I click the button. So what to do?

Simple: Add a animation from the add button to the cart. That way you communicate what just happened. “The product moved in there, and by clicking the cart you’ll find it again. Now continue buying stuff!”.

Somebody must have done this before, so I started looking for a jQuery plugin to do this (jQuery was already on the page, so why not?). I found add2cart – A plugin that looks good, but that misses a few features I wanted:

  • The animation duration is set in seconds, meaning products further down the page will move faster than those further up. I wanted constant speed.
  • It didn’t allow me to customize the look of the animated element.
  • The code rely on concatenating strings of CSS and generally could use lots of improvement.

So I did what anyone would do: rewrote the code from scratch, and posted it on GitHub.


Animate From To 1.0, by Emil Stenström


It’s my first jQuery plugin ever, and my first public GitHub project, so let me know if I’ve done something wrong. Is this something that could be useful in one of your projects?

Get Your Apps to Customers 5X Faster with RAD Studio. Brought to you in partnership with Embarcadero.


Published at DZone with permission of Emil Stenström. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}