Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #624 to auto-calc tween values for css type values using Window.getComputedStyle(). #669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ function normalizeTweens(prop, animatable) {
return prop.tweens.map(t => {
const tween = normalizeTweenValues(t, animatable);
const tweenValue = tween.value;
let to = is.arr(tweenValue) ? tweenValue[1] : tweenValue;
let to = calcTweenValue(animatable.target, prop.name, is.arr(tweenValue) ? tweenValue[1] : tweenValue);
const toUnit = getUnit(to);
const originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable);
const previousValue = previousTween ? previousTween.to.original : originalValue;
const from = is.arr(tweenValue) ? tweenValue[0] : previousValue;
const from = calcTweenValue(animatable.target, prop.name, is.arr(tweenValue) ? tweenValue[0] : previousValue);
const fromUnit = getUnit(from) || getUnit(originalValue);
const unit = toUnit || fromUnit;
if (is.und(to)) to = previousValue;
Expand All @@ -736,6 +736,24 @@ function normalizeTweens(prop, animatable) {
});
}

function calcTweenValue(el, propName, value) {
switch (getAnimationType(el, propName)) {
case 'css': return calcCssTweenValue(el, propName, value);
default: return value;
}
}

// calculate css value from obscure values like 'auto'
function calcCssTweenValue(el, propName, value) {
if(getUnit(value) !== undefined){ return value } // no calculation required
let uppercasePropName = propName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
let currentValue = el.style[propName];
el.style[propName] = value; // temporarily change value
let tweenValue = getComputedStyle(el).getPropertyValue(uppercasePropName) || value;
el.style[propName] = currentValue; // reset original value
return tweenValue;
}

// Tween progress

const setProgressValue = {
Expand Down