juliangarnier / anime

JavaScript animation engine

Home Page:https://animejs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to target nested object properties?

kevinschaich opened this issue · comments

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?

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.

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!

commented

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,
    ...
})