Jump to content
Search Community

Tween value only, not an object property

Mike D test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi guys,

 

Does anyone know how to creat the equivalent of this TWEEN function using Greensock?

new TWEEN.Tween({ val: 0 })
            .to({ val: 1 }, 500)
            .easing(TWEEN.Easing.Circular.InOut)
            .onUpdate(function () {

               // some logic here
            })
            .onComplete(function () {
                // some logic here
            }).start();

Thank you.

Link to comment
Share on other sites

The property you tween must belong to some object, but any generic JS object will do.

The target of your tween does not need to be a DOM element or anything.

 

I had this laying around:

//TweenLite can tween any numeric property of any object


var game = {score:0},
    add20Btn = document.getElementById("add20Btn");
scoreDisplay = document.getElementById("score");


add20Btn.onclick = add20;


function add20() {
  TweenLite.to(game, 1, {score:"+=20", roundProps:"score", onUpdate:updateHandler, ease:Linear.easeNone});
}


function updateHandler() {
  scoreDisplay.innerHTML = game.score;
}


add20();

 

http://codepen.io/GreenSock/pen/hzfji

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...