GithubHelp home page GithubHelp logo

jquery-animate_from_to's Introduction

Animate from to v1.0 - a jQuery plugin

This is a simple jQuery plugin with one simple purpose: to give the impression of movement from one element to another. This is useful for instance for a web shop when you want show that a product was added to the cart. The idea is based on another plugin called add2cart, but all of the code is rewritten and made more flexible.

Tested in Firefox 10, IE 7-9, Chrome 17, Opera 10, Safari 5, and probably many more. It's not that much code, so if you find some bug it's easy to fix.

Note: You need to be in standards mode for this to work. In IE, use: <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

Who did this?

Quickstart

Usage

Arguments and construction:

$(sourceElm).animate_from_to(targetElm [, options]);

Basic, bare bones example with real arguments:

$("#area-1").animate_from_to("#area-2");

It's also possible to use this construct:

$.animate_from_to(sourceElm, targetElm, [, options]);

Example

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="jquery.animate_from_to-1.0.js"></script>
<script>
    $(document).ready(function(){
        $("#button1").click(function(){
            $('#prod_123').animate_from_to('#cart');
        });
    });
</script>

<span id="cart">
    My shopping cart
</span>


<div id="prod_123" style="height: 100px; width:300px; margin-top: 100px; background: pink">
    <form onsubmit="return false;">
        <button type="submit" id="button1">Add to cart</button>
    </form>
</div>

Customization

Slow the speed of the animation:

$('#prod_123').animate_from_to('#cart', {
    pixels_per_second: 1000
});

Slow the speed and make the animated element blue:

$('#prod_123').animate_from_to('#cart', {
    pixels_per_second: 1000,
    initial_css: {
        'background': 'blue'
    }
});

Call the function of your choice when the animation finishes:

$('#prod_123').animate_from_to('#cart', {
    callback: function(){
		alert('Animation done');
	}
});

Options

This is what the different arguments mean:

sourceElm (required)

Element to start the animation from. Can be either a selector or a DOM element.

targetElm (required)

Element where the animation ends

options (optional, default: {})

  • pixels_per_second (optional, default: 3000). Speed of the animation, in number of pixels per elapsed second. This makes the animation move with constant same speed no matter where on the page the element is.

  • initial_css (optional, default: [See source]). Object literal. A way to override the default CSS of the "shadow" element that is part of the animation.

  • image (optional, default: ''). URL to image that will be used instead of a blank div

  • square (optional, default: ''). There are two options height: Will keep the animated div square, and animate it to the targets height width: Will keep the animated div square, and animate it to the targets width

  • callback (optional, default: [Dummy function that does nothing]). Function. A callback that will be called when the animation finishes.

A custom call would hence look like this:

$("#prod_123").animate_from_to("#cart", {
    pixels_per_second: 1000,
    initial_css: {
        "color": "red",
        "background-color": blue
    },
    callback: function(){
        alert("Completed!");
    }
});

License

Copyright (c) 2011 Emil Stenstrom https://friendlybit.com

Dual licensed under the MIT and GPL licenses:

jquery-animate_from_to's People

Contributors

emilstenstrom avatar johanbrook avatar johncongdon avatar puggan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.