Code Monkey home page Code Monkey logo

tinytween's Introduction

tinyTween.js

I was commissioned to create a banner and hade limited of kb to use, therefor I created tinyTween. It's only around 600 b gzipped, around 1kb uncompressed, when minified.

Call it like this:

tw.tween(from, to, dur, onStep, onComplete)
  • from and to is any numeric value
  • dur is in seconds
  • onStep is a function and is called with an object containing current value and current progress.
  • onStep is also called at the end together with the onComplete function.
  • onComplete is called when the tween is done and has no data in the call.

Example:

//First catch the element to tween.
var $el = document.getElementById('d1')

//Then set up the tween.
var myTw = tw.tween(10, 600, 0.8, function(data) {
    //Do your stuff on the tick callback.
    $el.style.left = data.val + 'px';
}, function() {
    console.log('Complete!!');
});

//Seek like this
myTw.seek(0.5);

I also created tinyTweenUtils with utils to make some recurrent actions easier to do.

Example:

tw.x('#d1', {
    to: 600
});

tw.y('#d1', {
    to: 300
});

tw.scale('#d1', {
    to: 3
});

tw.rotate('#d1', {
    to: 180
});

tw.rotate('#d2', {
    to: 720,
    dur: 3
});

And to que animations:

var tl = new tw.Q({
    onComplete: function() {
        tl.play();
    }
});

tl.add({t: '#d1', what: 'x', to: 200, dur: 0.3});
tl.add({t: '#d1', what: 'y', to: 200, dur: 0.3});
tl.add({t: '#d1', what: 'scale', to: 1.4, dur: 0.3});
tl.add({t: '#d1', what: 'rotate', to: 360, dur: 0.6});
tl.add({t: '#d1', what: 'opacity', to: 0, dur: 0.3});
tl.add({t: '#d1', what: 'opacity', to: 1, dur: 0.5});

tl.add({t: '#d1', what: 'x', to: 10, dur: 0.3});
tl.add({t: '#d1', what: 'y', to: 10, dur: 0.3});
tl.add({t: '#d1', what: 'scale', to: 1, dur: 0.3});
tl.add({t: '#d1', what: 'rotate', to: -360, dur: 0.6});

tl.play();

tinytween's People

Contributors

arpo avatar

Watchers

James Cloos 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.