Skip to content

Commit

Permalink
Carousel: fix unresponsive navigation (#34678)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieur-z authored Dec 15, 2023
1 parent 12712d2 commit 67cc302
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Carousel: fix unresponsive navigation
26 changes: 13 additions & 13 deletions projects/plugins/jetpack/modules/carousel/jetpack-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,39 +116,39 @@
// Ensure the item is in the render tree, in its initial state.
el.style.removeProperty( 'display' );
el.style.opacity = start;
el.style.transition = 'opacity 0.2s';
el.style.pointerEvents = 'none';

var finished = function ( e ) {
if ( e.target === el && e.propertyName === 'opacity' ) {
el.style.removeProperty( 'transition' );
el.style.removeProperty( 'opacity' );
var animate = function ( t0, duration ) {
var t = performance.now();
var diff = t - t0;
var ratio = diff / duration;

if ( ratio < 1 ) {
el.style.opacity = start + ( end - start ) * ratio;
requestAnimationFrame( () => animate( t0, duration ) );
} else {
el.style.opacity = end;
el.style.removeProperty( 'pointer-events' );
el.removeEventListener( 'transitionend', finished );
el.removeEventListener( 'transitioncancel', finished );
callback();
}
};

requestAnimationFrame( function () {
// Double rAF for browser compatibility.
requestAnimationFrame( function () {
el.addEventListener( 'transitionend', finished );
el.addEventListener( 'transitioncancel', finished );
// Trigger transition.
el.style.opacity = end;
animate( performance.now(), 200 );
} );
} );
}

function fadeIn( el, callback ) {
callback = callback || util.noop;
fade( el, '0', '1', callback );
fade( el, 0, 1, callback );
}

function fadeOut( el, callback ) {
callback = callback || util.noop;
fade( el, '1', '0', function () {
fade( el, 1, 0, function () {
if ( el ) {
el.style.display = 'none';
}
Expand Down

0 comments on commit 67cc302

Please sign in to comment.