juliangarnier / anime

JavaScript animation engine
https://animejs.com
MIT License
50.4k stars 3.68k forks source link

Is it possible to target nested object properties? #842

Open kevinschaich opened 1 year ago

kevinschaich commented 1 year ago

e.g. I have:

const myObject = {
    a: {
        b: {
            c: 1000
        }
    }
}

Can I somehow tell anime that I want 'c' to change? via dot notation a.b.c or similar?

different55 commented 1 year ago

Yeah, you'd use dot notation. Not somewhere where I can cough up a mini example but check out the docs. They show how to target an arbitrary JavaScript object and animate its properties. But I believe you'd target a.b and then set c to whatever values/keyframes.

kevinschaich commented 1 year ago

For right now since we couldn't find any example code, I decided to just "flatten" my object to make the top-level keys strings:

const myObject = {
    'a.b.c': 1000
}

and in anime:

anime({
    targets: myObject,
    'a.b.c': 2000,
    ...
})

Let me know if anyone has a better way!

PAEz commented 1 year ago

Never rEaLlY used this library, but just looking at what is said here then wouldnt it just be.....

anime({
    targets: myObject.a.b,
    'c': 2000,
    ...
})