Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change values to track dynamically #93

Closed
alyrik opened this issue Oct 7, 2015 · 2 comments
Closed

Change values to track dynamically #93

alyrik opened this issue Oct 7, 2015 · 2 comments

Comments

@alyrik
Copy link

alyrik commented Oct 7, 2015

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.

@mattgperry
Copy link
Collaborator

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!

@alyrik
Copy link
Author

alyrik commented Oct 8, 2015

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 alyrik closed this as completed Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants