diff --git a/aio/e2e/app.po.ts b/aio/e2e/app.po.ts index 0d7568178f..dde2ffd955 100644 --- a/aio/e2e/app.po.ts +++ b/aio/e2e/app.po.ts @@ -29,7 +29,10 @@ export class SitePage { locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise; } navigateTo(pageUrl) { - return browser.get('/' + pageUrl).then(() => browser.waitForAngular()); + // Navigate to the page, disable animations, and wait for Angular. + return browser.get('/' + pageUrl) + .then(() => browser.executeScript('document.body.classList.add(\'no-animations\')')) + .then(() => browser.waitForAngular()); } getDocViewerText() { diff --git a/aio/src/app/layout/doc-viewer/doc-viewer.component.ts b/aio/src/app/layout/doc-viewer/doc-viewer.component.ts index 0580f27778..9f587a02b3 100644 --- a/aio/src/app/layout/doc-viewer/doc-viewer.component.ts +++ b/aio/src/app/layout/doc-viewer/doc-viewer.component.ts @@ -176,6 +176,14 @@ export class DocViewerComponent implements DoCheck, OnDestroy { return () => cancelAnimationFrame(rafId); }); + // Get the actual transition duration (taking global styles into account). + // According to the [CSSOM spec](https://drafts.csswg.org/cssom/#serializing-css-values), + // `time` values should be returned in seconds. + const getActualDuration = (elem: HTMLElement) => { + const cssValue = getComputedStyle(elem).transitionDuration; + const seconds = Number(cssValue.replace(/s$/, '')); + return 1000 * seconds; + }; const animateProp = (elem: HTMLElement, prop: string, from: string, to: string, duration = 333) => { elem.style.transition = ''; @@ -189,7 +197,7 @@ export class DocViewerComponent implements DoCheck, OnDestroy { .switchMap(() => raf$).do(() => elem.style[prop] = from) .switchMap(() => raf$).do(() => elem.style.transition = `all ${duration}ms ease-in-out`) .switchMap(() => raf$).do(() => elem.style[prop] = to) - .switchMap(() => timer(duration)).switchMap(() => this.void$); + .switchMap(() => timer(getActualDuration(elem))).switchMap(() => this.void$); }; const animateLeave = (elem: HTMLElement) => animateProp(elem, 'opacity', '1', '0.25'); diff --git a/aio/src/styles/1-layouts/_doc-viewer.scss b/aio/src/styles/1-layouts/_doc-viewer.scss new file mode 100644 index 0000000000..928f2c666b --- /dev/null +++ b/aio/src/styles/1-layouts/_doc-viewer.scss @@ -0,0 +1,4 @@ +.no-animations aio-doc-viewer > * { + // Disable view transition animations. + transition: none !important; +} diff --git a/aio/src/styles/1-layouts/_layouts-dir.scss b/aio/src/styles/1-layouts/_layouts-dir.scss index f6269f1f95..93311dc79d 100644 --- a/aio/src/styles/1-layouts/_layouts-dir.scss +++ b/aio/src/styles/1-layouts/_layouts-dir.scss @@ -4,6 +4,7 @@ @import 'api-page'; @import 'content-layout'; +@import 'doc-viewer'; @import 'footer'; @import 'layout-global'; @import 'marketing-layout';