Skip to content

Commit

Permalink
Ensure style recalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Jan 30, 2017
1 parent 84d465d commit 22d09ee
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lib/core/ripple/ripple-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ export class RippleRenderer {

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

this._targetElement.appendChild(ripple);

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

ripple.style.transform = 'scale(1)';

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

0 comments on commit 22d09ee

Please sign in to comment.