Skip to content

[FEATURE] alternative solutions for dynamic value like tween.js #1042

@littleboarx

Description

@littleboarx

Describe what the feature does

Since animejs is great, there is still no alternative solution like dynamic in tween.js, .refesh() this close, but it changes the from value ,so there should

Provide a code example of what the feature should look like

The easiest way is to add parameters in the refresh API

    /**
     * @param {boolean} keepFrom
     * @return {this}
     */
    refresh(keepFrom = false) {
        forEachChildren(this, (/** @type {Tween} */ tween) => {
            const ogValue = getOriginalAnimatableValue(tween.target, tween.property, tween._tweenType);
            decomposeRawValue(ogValue, decomposedOriginalValue);
            if(!keepFrom) {
                tween._fromNumbers = cloneArray(decomposedOriginalValue.d);
                tween._fromNumber = decomposedOriginalValue.n;
            }
            if (tween._func) {
                decomposeRawValue(tween._func(), toTargetObject);
                tween._toNumbers = cloneArray(toTargetObject.d);
                tween._strings = cloneArray(toTargetObject.s);
                tween._toNumber = toTargetObject.n;
            }
        });
        return this;
    }

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Solution 2: add dynamic props on the Tween animation:

const animation = animate(targets, {
   x: {
     to: () => Math.random() * 100,
      dynamic: true  // mark as dynamic
    }
  });

Solution 3: add another animation API:

  const animation = animate(targets, {
    x: {
     to: () => Math.random() * 100,
    }
  });
animation.updateDynamic(); 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions