The element to update the css variable to. This can be the body element if you want a "global" css variable or you can specific a more speicific element to scope the results of your css variables.
Optionalconfig: multiInterpolateConfigInternal instance of element visibility.
Whether to prevent DOM render updates when the element is out of view. This prevents this class from updating the element style or css variables if it is out of view. The default is true to provide performance benefits.
Whether to run update once after the element goes out of view so the state of interpololations are correctly resolved to its starting state when elements come back into view. The default is true.
Flushes the update cache. By default, two consecutive calls to update with the same progress values will cull the second call for performance booosts. However, there are rare cases where you may want to update with the same progress values and force an update to the variable. Calling flush will flush the internal cache.
cssVarInterpolate.update(0.2);
cssVarInterpolate.update(0.2); // Normally gets ignored
cssVarInterpolate.update(0.2);
cssVarInterpolate.flush(); // Flush cache
cssVarInterpolate.update(0.2); // Will update.
Gets the last set of calculated values. This will return an empty object if no updates / calculations have been run. If updates have been executed, it will return an object with each css-var property value.
Sets css var interpolate to render even when out of view.
Updates the internal interpolations. Use this to update your interpolations.
let ci = new CssVarInterpolate(element);
ci.setInterpolations({
interpolations: [
{
progress: [
{ from: 0, to: 1, start: 0, end: 500 },
],
id: '--x'
}
]
});
Sets the internal precision. Precision is used to evaluate how many decimals should be valuated on progress. Lower precision means, 0.8888 and 0.88888 would be same. Enter the number of decimals you want to account for. Lower precision will have slight performance benefits.
Sets the start and end values of which interpolations begin. This allows you to set something like, given the main progress that is updated from 0-1, I only want this to interpolate from 0.2-0.6.
Updates the progress and updates the css variable values.
Allows you to bypass the cache. By default two consecutive calls to update WITH the same progress values will cull the second call. Force allows you to force it to render again.
Allows batch update of css variables. Recommend for improved performance.
Sets css-var-interpolate to no write mode in which it will only calculate values but not write them to the dom. This is used for cases in which you want use the class to calculate values but take control of when and where writing happens.
Toggles subpixel rendering. When subpixel rendering is turned off, 'px' value interpolations will be turned into whole numbers. Subpixel rendering is turned on by default but can be turned off for performance boosts.
A class that allows you to multiInterpolate css variables.
JS
Ranged Progress Interpolations You can also set the progress range. This will tell cssVarInterpolate to internally generate a [[mathf.childProgress]] and scope the interpolations to a scoped range instead of 0-1.
Element Visibility CssVarInterpolate by default will only update css variables when the root element is inview to performance reasons.
If you want to turn this off, do the following:
// No write mode. There are times you may just want to use the css-var-interpolate to just calculate values for you.
You can prevent css-var-interpolate from writing to the dom with:
then you can do something like this to get the values.