Fix: only parseFloat for the values necessary in the transition

pull/6183/head
Theo-Steiner 5 years ago committed by Theodor Steiner
parent bd33b89634
commit d1c5b6fd2e

@ -107,15 +107,17 @@ export function slide(node: Element, {
easing = cubicOut, easing = cubicOut,
axis = 'y' axis = 'y'
}: SlideParams = {}): TransitionConfig { }: SlideParams = {}): TransitionConfig {
const direction: { x: 1 | 0, y: 1 | 0 } = { x: axis === 'x' ? 1 : 0, y: axis === 'y' ? 1 : 0 };
const style = getComputedStyle(node); const style = getComputedStyle(node);
const opacity = +style.opacity; const opacity = +style.opacity;
const height = parseFloat(style.height); const primary_dimension = axis === 'y' ? 'height' : 'width';
const width = parseFloat(style.width); const primary_dimension_value = parseFloat(style[primary_dimension]);
const padding = { top: parseFloat(style.paddingTop), right: parseFloat(style.paddingRight), bottom: parseFloat(style.paddingBottom), left: parseFloat(style.paddingLeft) }; const secondary_dimensions = axis === 'y' ? ['Top', 'Bottom'] : ['Left', 'Right'];
const margin = { top: parseFloat(style.marginTop), right: parseFloat(style.marginRight), bottom: parseFloat(style.marginBottom), left: parseFloat(style.marginLeft) }; const padding_first_value = parseFloat(style.padding[secondary_dimensions[0]]);
const border_width = { top: parseFloat(style.borderTopWidth), right: parseFloat(style.borderRightWidth), bottom: parseFloat(style.borderBottomWidth), left: parseFloat(style.borderLeftWidth) }; const padding_second_value = parseFloat(style.padding[secondary_dimensions[1]]);
const margin_first_value = parseFloat(style.margin[secondary_dimensions[0]]);
const margin_second_value = parseFloat(style.margin[secondary_dimensions[1]]);
const border_width_first_value = parseFloat(style['border'.concat(secondary_dimensions[0].concat('Width'))]);
const border_width_second_value = parseFloat(style['border'.concat(secondary_dimensions[1].concat('Width'))]);
return { return {
delay, delay,
duration, duration,
@ -123,11 +125,13 @@ export function slide(node: Element, {
css: t => css: t =>
'overflow: hidden;' + 'overflow: hidden;' +
`opacity: ${Math.min(t * 20, 1) * opacity};` + `opacity: ${Math.min(t * 20, 1) * opacity};` +
`height: ${t ** direction.y * height}px;` + `${primary_dimension}: ${t * primary_dimension_value}px;` +
`width: ${t ** direction.x * width}px;` + `padding-${secondary_dimensions[0].toLowerCase()}: ${t * padding_first_value}px;` +
`padding: ${t ** direction.y * padding.top}px ${t ** direction.x * padding.right}px ${t ** direction.y * padding.bottom}px) ${t ** direction.x * padding.left}px;` + `padding-${secondary_dimensions[1].toLowerCase()}: ${t * padding_second_value}px;` +
`margin: ${t ** direction.y * margin.top}px ${t ** direction.x * margin.right}px ${t ** direction.y * margin.bottom}px ${t ** direction.x * margin.left}px;` + `margin-${secondary_dimensions[0].toLowerCase()}: ${t * margin_first_value}px;` +
`border-width: ${t ** direction.y * border_width.top}px ${t ** direction.x * border_width.right}px ${t ** direction.y * border_width.bottom}px ${t ** direction.x * border_width.left}px;` `margin-${secondary_dimensions[1].toLowerCase()}: ${t * margin_second_value}px;` +
`border-${secondary_dimensions[0].toLowerCase()}-width: ${t * border_width_first_value}px;` +
`border-${secondary_dimensions[1].toLowerCase()}-width: ${t * border_width_second_value}px;`
}; };
} }

Loading…
Cancel
Save