fix animations intermittently not triggering in firefox

This commit is contained in:
Hakim El Hattab 2020-02-17 09:50:01 +01:00
parent c38bc2c611
commit f263f2819d

View file

@ -3852,20 +3852,22 @@
*/
function autoAnimate( fromSlide, toSlide ) {
// Remove any existing auto-animate sheet. Recycling led to
// animations sometimes not trigger in FF.
// Clean up after prior animations
removeEphemeralAutoAnimateAttributes();
if( autoAnimateStyleSheet && autoAnimateStyleSheet.parentNode ) {
autoAnimateStyleSheet.parentNode.removeChild( autoAnimateStyleSheet );
autoAnimateStyleSheet = null;
}
// Create a new auto-animate sheet
autoAnimateStyleSheet = document.createElement( 'style' );
autoAnimateStyleSheet.type = 'text/css';
document.head.appendChild( autoAnimateStyleSheet );
// Ensure that both slides are auto-animate targets
if( fromSlide.hasAttribute( 'data-auto-animate' ) && toSlide.hasAttribute( 'data-auto-animate' ) ) {
// Clean up after prior animations
removeEphemeralAutoAnimateAttributes();
// Create a new auto-animate sheet
autoAnimateStyleSheet = autoAnimateStyleSheet || document.createElement( 'style' );
autoAnimateStyleSheet.type = 'text/css';
autoAnimateStyleSheet.className = 'auto-animate-styes';
document.head.appendChild( autoAnimateStyleSheet );
var slideOptions = getAutoAnimateOptions( toSlide, {
@ -3876,11 +3878,9 @@
} );
// Set our starting state. Note that we may be coming from, or
// going to, a non-auto-animate slide so we only want to assign
// this value is the attribute exists.
if( typeof fromSlide.dataset.autoAnimate === 'string' ) fromSlide.dataset.autoAnimate = 'pending';
if( typeof toSlide.dataset.autoAnimate === 'string' ) toSlide.dataset.autoAnimate = 'pending';
// Set our starting state
fromSlide.dataset.autoAnimate = 'pending';
toSlide.dataset.autoAnimate = 'pending';
// Inject our auto-animate styles for this transition
var css = getAutoAnimatableElements( fromSlide, toSlide ).map( function( elements ) {
@ -3903,9 +3903,14 @@
autoAnimateStyleSheet.innerHTML = css.join( '' );
// Start the animation next cycle
setTimeout( function() {
if( typeof toSlide.dataset.autoAnimate === 'string' ) toSlide.dataset.autoAnimate = 'running';
}, 2 );
requestAnimationFrame( function() {
// This forces our newly injected styles to be applied in Firefox
getComputedStyle( autoAnimateStyleSheet ).fontWeight;
toSlide.dataset.autoAnimate = 'running';
} );
}
}
@ -4076,7 +4081,7 @@
properties.height = element.offsetHeight;
}
var computedStyles = window.getComputedStyle( element );
var computedStyles = getComputedStyle( element );
// CSS styles
( elementOptions.styles || config.autoAnimateStyles ).forEach( function( style ) {