Giter Club home page Giter Club logo

jquery.transformlist's Introduction

jquery.transformlist - a CSS3 transform animation plugin for jQuery

jquery.transformlist is a Javascript plugin for jQuery to add support for styling and correctly animating CSS3 transforms that make use of multiple transform functions.

jquery.transformlist is not intended to provide animation between arbitrary transform styles - it doesn't provide the matrix decomposition required for that task. Instead it aims to assist you in creating a transform list of several transform functions that are composited for a specific task, and then provides you with means to use jQuery.animate() between different sets of arguments for those transform functions.

That's a little unclear, so imagine you set up a "camera" transform list allowing you to adjust the X, Y, and Z of the focal point; and then the rotation around, elevation above or below, and distance from the focal point.

jquery.transformlist then lets you animate between any different set of those values, using all the power and features of jQuery.animate().

To take it a step further, you could create a transform list to style and position a scene, a transform list for positioning of objects/elements within that scene, and finally a transform list for the camera view of the scene. You could then animate individual objects within the scene using the positioning transform list, while independently animating the camera view of the scene.

For some examples, check below, or for a demonstration please visit the plugin website:

Setup

Save plugin somewhere and include in your page after you load jQuery:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="/js/jquery.transformlist.js"></script>

Then define a named "camera" transform list with 6 named transforms and default values:

$.TransformList('camera')
    .addTransform('focalX',             'translateX', '0px')
    .addTransform('focalY',             'translateY', '0px')
    .addTransform('focalHeight',        'translateZ', '0px')
    .addTransform('cameraRotation',     'rotateY',    '30deg')
    .addTransform('cameraElevation',    'rotateX',    '25deg')
    .addTransform('cameraDistance',     'translateZ', '250px');

Style an element with the transform list:

$('.camera').css('transformlist', {
    transformlist: 'camera',
    focalX:        '50px',
    focalY:        '25px'
    });

Animate an element to new values in the transform list:

$('.camera').animate({
    transformlist: {
        transformlist:   'camera',
        focalX:          '20px',
        focalY:          '+=30px',
        cameraRotation:  '75deg',
        cameraElevation: '-=10deg'
        }
    }, 1000, 'linear');

Interrupt the last animation with stop and animate from the interrupted position:

$('.camera').stop(true).animate({
    transformlist: {
        transformlist:   'camera',
        focalX:          '0px',
        focalY:          '0px',
        cameraRotation:  '0deg',
        cameraElevation: '5deg',
        cameraDistance:  '25px'
        }
    }, 300, 'linear');

Query the current tranform list:

// Super verbose for your reading pleasure.
var transformlist = $('.camera').css('transformlist');
var cameraRotationArgs = transformlist.transform('cameraRotation');
var firstArgWithUnits = cameraRotationArgs[0];
var cameraRotationWithoutUnits = parseFloat(firstArgWithUnits);

// Or all-in-one for maximum unreadability.
if (parseFloat($('.camera').css('transformlist').transform('cameraRotation')[0]) >= 720) {
    console.log("Dizzy nao, plz stop, k?");
}

Have fun.

See Also

Known Issues & Bugs

  • Not a bug, but you can't animate between different kinds of transformlist. I consider this a feature since it's not the target intent of the plugin. :)

License

GPL version 3, see LICENSE.txt for full license text.

jquery.transformlist's People

Contributors

illusori avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.