Skip to content

Commit 22d09ee

Browse files
committed
Ensure style recalculation
1 parent 84d465d commit 22d09ee

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/lib/core/ripple/ripple-renderer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,17 @@ export class RippleRenderer {
9393

9494
// If the color is not set, the default CSS color will be used.
9595
ripple.style.backgroundColor = config.color;
96+
ripple.style.transitionDuration = `${duration}s`;
9697

9798
this._targetElement.appendChild(ripple);
9899

99-
// Wait for the next tick because for elements the CSS transition isn't applied
100-
// immediately and otherwise the ripple would just expand without any animation.
101-
this.runTimeoutOutsideZone(() => {
102-
ripple.style.transitionDuration = `${duration}s`;
103-
ripple.style.transform = 'scale(1)';
104-
}, 1);
100+
// By default the browser does not recalculate the styles of dynamically created
101+
// ripple elements. This is critical because then the `scale` would not animate properly.
102+
// Enforce a style recalculation by calling `getComputedStyle` and accessing any property.
103+
// See: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
104+
window.getComputedStyle(ripple).getPropertyValue('opacity');
105+
106+
ripple.style.transform = 'scale(1)';
105107

106108
// Wait for the ripple to be faded in. Once faded in the ripple can be hided if the mouse is
107109
// released.

0 commit comments

Comments
 (0)