Commit 562e9ac3 authored by kristipark's avatar kristipark Committed by Commit Bot

[NTP] Fix floating ripple effect

Position the ripple container relative to the element instead of the
viewport. This will allow the ripple effect to transition with the
element instead of floating in place.

https://screencast.googleplex.com/cast/NDg3NjY2Njc1Mjk5MTIzMnxlNzNlODU3My1jOQ

Bug: 864823
Change-Id: I4352ff9792d16aaa59f610634d71bb46362141b0
Reviewed-on: https://chromium-review.googlesource.com/1184035
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585240}
parent 6755efb1
...@@ -608,6 +608,7 @@ html[dir=rtl] #mv-notice-x { ...@@ -608,6 +608,7 @@ html[dir=rtl] #mv-notice-x {
color: rgb(26,115,232); color: rgb(26,115,232);
margin-inline-start: 0; margin-inline-start: 0;
padding: 0 16px; padding: 0 16px;
position: relative;
} }
#mv-notice-links span:hover, #mv-notice-links span:hover,
...@@ -715,14 +716,22 @@ html[dir=rtl] #attribution, ...@@ -715,14 +716,22 @@ html[dir=rtl] #attribution,
} }
.ripple-container { .ripple-container {
height: 100%;
left: 0;
pointer-events: none;
position: absolute;
top: 0;
width: 100%;
z-index: 100;
}
.ripple-effect-mask {
height: 0; height: 0;
left: 0; left: 0;
overflow: hidden; overflow: hidden;
pointer-events: none;
position: absolute; position: absolute;
top: 0; top: 0;
width: 0; width: 0;
z-index: 100;
} }
.ripple-effect { .ripple-effect {
......
...@@ -101,6 +101,7 @@ var CLASSES = { ...@@ -101,6 +101,7 @@ var CLASSES = {
// Applies ripple animation to the element on click // Applies ripple animation to the element on click
RIPPLE: 'ripple', RIPPLE: 'ripple',
RIPPLE_CONTAINER: 'ripple-container', RIPPLE_CONTAINER: 'ripple-container',
RIPPLE_EFFECT_MASK: 'ripple-effect-mask',
RIPPLE_EFFECT: 'ripple-effect', RIPPLE_EFFECT: 'ripple-effect',
// Applies drag focus style to the fakebox // Applies drag focus style to the fakebox
FAKEBOX_DRAG_FOCUS: 'fakebox-drag-focused', FAKEBOX_DRAG_FOCUS: 'fakebox-drag-focused',
...@@ -839,7 +840,8 @@ function enableMD() { ...@@ -839,7 +840,8 @@ function enableMD() {
/** /**
* Enables ripple animations for elements with CLASSES.RIPPLE. * Enables ripple animations for elements with CLASSES.RIPPLE. The target
* element must have position relative or absolute.
* TODO(kristipark): Remove after migrating to WebUI. * TODO(kristipark): Remove after migrating to WebUI.
*/ */
function addRippleAnimations() { function addRippleAnimations() {
...@@ -868,22 +870,22 @@ function addRippleAnimations() { ...@@ -868,22 +870,22 @@ function addRippleAnimations() {
Math.min(RIPPLE_MAX_RADIUS_PX, Math.max.apply(Math, cornerDistances)); Math.min(RIPPLE_MAX_RADIUS_PX, Math.max.apply(Math, cornerDistances));
let ripple = document.createElement('div'); let ripple = document.createElement('div');
let rippleMask = document.createElement('div');
let rippleContainer = document.createElement('div'); let rippleContainer = document.createElement('div');
ripple.classList.add(CLASSES.RIPPLE_EFFECT); ripple.classList.add(CLASSES.RIPPLE_EFFECT);
rippleMask.classList.add(CLASSES.RIPPLE_EFFECT_MASK);
rippleContainer.classList.add(CLASSES.RIPPLE_CONTAINER); rippleContainer.classList.add(CLASSES.RIPPLE_CONTAINER);
rippleContainer.appendChild(ripple); rippleMask.appendChild(ripple);
rippleContainer.appendChild(rippleMask);
target.appendChild(rippleContainer); target.appendChild(rippleContainer);
// Ripple start location // Ripple start location
ripple.style.marginLeft = x + 'px'; ripple.style.marginLeft = x + 'px';
ripple.style.marginTop = y + 'px'; ripple.style.marginTop = y + 'px';
rippleContainer.style.left = rect.left + 'px'; rippleMask.style.width = target.offsetWidth + 'px';
rippleContainer.style.top = rect.top + 'px'; rippleMask.style.height = target.offsetHeight + 'px';
rippleContainer.style.width = target.offsetWidth + 'px'; rippleMask.style.borderRadius =
rippleContainer.style.height = target.offsetHeight + 'px';
rippleContainer.style.borderRadius =
window.getComputedStyle(target).borderRadius; window.getComputedStyle(target).borderRadius;
rippleContainer.style.position = 'fixed';
// Start transition/ripple // Start transition/ripple
ripple.style.width = radius * 2 + 'px'; ripple.style.width = radius * 2 + 'px';
...@@ -894,6 +896,7 @@ function addRippleAnimations() { ...@@ -894,6 +896,7 @@ function addRippleAnimations() {
window.setTimeout(function() { window.setTimeout(function() {
ripple.remove(); ripple.remove();
rippleMask.remove();
rippleContainer.remove(); rippleContainer.remove();
}, RIPPLE_DURATION_MS); }, RIPPLE_DURATION_MS);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment