-
Notifications
You must be signed in to change notification settings - Fork 86
Property Filters
Caleb edited this page Dec 24, 2019
·
1 revision
Property filters map the instantaneous value (vd.val
output) of a property to a new value. They are useful for applying custom logic to the output of a keyframe set or function at a given time.
class CustomLayer extends vd.layer.Base {
constructor(startTime, duration, foo, options={}) {
this.foo = foo
}
}
CustomLayer.prototype._propertyFilters = {
...vd.layer.Base._propertyFilters,
foo: foo => Math.max(0, Math.min(foo, 1)) // clamp between 0 and 1
}
Now, you can access the value as usual:
const layer = new CustomLayer(0, 3, 2 * Math.random())
console.log(layer.foo) // This will never exceed 1, regardless of the input to `foo`