popmotion icon indicating copy to clipboard operation
popmotion copied to clipboard

Change values to track dynamically

Open alyrik opened this issue 11 years ago • 2 comments

Is it possible to change values to track dynamically (just in motion)? For example: initially I'd like to track only y but as soon as y === 20px I'd like to track x as well.

alyrik avatar Oct 07 '15 16:10 alyrik

I've never tried this and I'm about to go AFK. But off the top of my head you could try it a few ways.

One would be to track both y and x at all times, but set a min and max of x to 0 - then when y === 20 yu could set yourActor.values.x.min = undefined and the same for max.

You could in theory make two Track classes, one for each axis, and then start the second later - but for various reasons that shouldn't be true I'm not sure it would work right now.

If these don't work I'll take a look tomorrow and get back to you. If it isn't possible, it should be!

mattgperry avatar Oct 07 '15 17:10 mattgperry

The first way works as expected, thank you!

Something like this:

let untied = false;

let actor = new popmotion.Actor({
    element: this.el,
}),
    track = new popmotion.Track({
        values: {
            x: {
                min: 0,
                max: 0
        },
            y: {}
        },
        onUpdate(frame) {
            let y = parseInt(frame.y);

            if (y < -20) {
                if (!untied) {
                    untied = true;
                    linkActor.values.x.min = undefined;
                    linkActor.values.x.max = undefined;
                }
            }
        }
    });

alyrik avatar Oct 08 '15 15:10 alyrik