⚠️ Fix most animations/transitions performance issues
All checks were successful
continuous-integration/drone/push Build is passing

- Basically add `will-change` to CSS elements to enable GPU animations, less choppy, more sassy
- Use requestAnimationFrame over setTimeout
- Avoid repaints AMAP
This commit is contained in:
2020-04-05 16:07:44 +02:00
parent 0b8086e63c
commit bd9b91f480
21 changed files with 129 additions and 89 deletions

View File

@@ -9,14 +9,15 @@ import { animDuration, animDelay } from 'utils/store'
export const animateIn = scope => { export const animateIn = scope => {
const tl = anime.timeline({ const tl = anime.timeline({
easing: 'easeOutQuart', easing: 'easeOutQuart',
duration: animDuration duration: animDuration,
delay: 0
}) })
// Photo: Active // Photo: Active
tl.add({ tl.add({
targets: scope.querySelector('.is-active picture'), targets: scope.querySelector('.is-active picture'),
translateY: [32, 0] translateY: [8, 0]
}) }, 100)
// Photo: Prev // Photo: Prev
tl.add({ tl.add({
targets: scope.querySelector('.is-prev picture'), targets: scope.querySelector('.is-prev picture'),
@@ -30,7 +31,7 @@ export const animateIn = scope => {
translateY: [8, 0], translateY: [8, 0],
translateX: [-48, 0], translateX: [-48, 0],
rotate: [2, 0] rotate: [2, 0]
}, 150) }, 100)
// Reveal on scroll // Reveal on scroll
const carouselIn = ScrollOut({ const carouselIn = ScrollOut({

View File

@@ -11,30 +11,33 @@ export const animateIn = scope => {
const locations = ScrollOut({ const locations = ScrollOut({
targets: scope.querySelectorAll('.location'), targets: scope.querySelectorAll('.location'),
onShown (el) { onShown (el) {
const tl = anime.timeline({
easing: 'easeOutQuart',
duration: 600
})
// Image // Image
tl.add({ anime({
targets: el.querySelector('img'), targets: el.querySelector('img'),
scale: [1.3, 1], scale: [1.3, 1],
opacity: [0, 1], opacity: [0, 1],
duration: 1800 easing: 'easeOutQuart',
}, 100) duration: 1800,
delay: 100
})
// Name // Name
tl.add({ anime({
targets: el.querySelector('h3'), targets: el.querySelector('h3'),
translateY: ['100%', 0] translateY: ['100%', 0],
}, 300) easing: 'easeOutQuart',
duration: 600,
delay: 300
})
// Country // Country
tl.add({ anime({
targets: el.querySelector('p'), targets: el.querySelector('p'),
translateY: ['100%', 0] translateY: ['100%', 0],
}, 550) easing: 'easeOutQuart',
duration: 600,
delay: 550
})
} }
}) })
} }

View File

@@ -66,7 +66,7 @@ export const animateIn = scope => {
autoplay: false autoplay: false
}) })
window.addEventListener('scroll', throttle(() => parallaxAnime(el, translate), 50)) window.addEventListener('scroll', throttle(() => parallaxAnime(el, translate), 50))
setTimeout(() => parallaxAnime(el, translate), 50) requestAnimationFrame(() => parallaxAnime(el, translate))
}, },
onHidden () { onHidden () {
if (parallaxAnime) window.removeEventListener('scroll', parallaxAnime) if (parallaxAnime) window.removeEventListener('scroll', parallaxAnime)

View File

@@ -11,7 +11,6 @@ export const animateIn = (scope, init) => {
easing: 'easeOutQuart', easing: 'easeOutQuart',
duration: 1000 duration: 1000
}) })
// Stagger each letters and words // Stagger each letters and words
tl.add({ tl.add({
targets: scope.querySelectorAll('span, em span'), targets: scope.querySelectorAll('span, em span'),

View File

@@ -17,16 +17,27 @@ export const animateIn = () => {
easing: 'easeOutQuart' easing: 'easeOutQuart'
}) })
// Carousel
const carousel = anime({
targets: document.querySelector('.intro .carousel'),
translateY: [32, 0],
opacity: [0, 1],
easing: 'easeOutQuart',
duration: animDuration,
delay: animDelay,
complete: event => event.animatables[0].target.removeAttribute('style')
})
// Parallax on scroll // Parallax on scroll
const translate = anime({ const translate = anime({
targets: '#title-houses', targets: '#title-houses',
translateX: ['7%', '-15%'], translateX: ['7%', '-15%'],
easing: 'linear', easing: 'linear',
autoplay: false, duration: animDuration,
duration: animDuration autoplay: false
}) })
window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 10)) window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 10))
setTimeout(() => parallaxAnime(document.getElementById('title-houses'), translate), 50) requestAnimationFrame(() => parallaxAnime(document.getElementById('title-houses'), translate), 50)
// Intro: Description // Intro: Description
const introDescription = anime({ const introDescription = anime({
@@ -38,23 +49,6 @@ export const animateIn = () => {
delay: anime.stagger(200, { start: animDelay + 200 }) delay: anime.stagger(200, { start: animDelay + 200 })
}) })
// Intro: Carousel revealing (scroll)
const introCarousel = ScrollOut({
once: true,
targets: '#intro-carousel',
onShown (el) {
anime({
targets: el,
opacity: [0, 1],
translateY: [24, 0],
easing: 'easeOutQuart',
duration: animDuration,
delay: animDelay + 400,
complete: event => event.animatables[0].target.removeAttribute('style')
})
}
})
// Title: Of (reveal on scroll) // Title: Of (reveal on scroll)
const titleOf = ScrollOut({ const titleOf = ScrollOut({
once: true, once: true,
@@ -71,6 +65,13 @@ export const animateIn = () => {
}) })
// Title: World (reveal on scroll) // Title: World (reveal on scroll)
const titleWorldTranslate = anime({
targets: document.getElementById('title-world'),
translateX: ['5%', '-3%'],
easing: 'linear',
autoplay: false,
duration: animDuration
})
const titleWorld = ScrollOut({ const titleWorld = ScrollOut({
once: true, once: true,
targets: document.getElementById('title-world'), targets: document.getElementById('title-world'),
@@ -82,15 +83,8 @@ export const animateIn = () => {
delay: anime.stagger(70), delay: anime.stagger(70),
duration: animDuration duration: animDuration
}) })
const titleWorldTranslate = anime({
targets: el,
translateX: ['5%', '-3%'],
easing: 'linear',
autoplay: false,
duration: animDuration
})
window.addEventListener('scroll', throttle(() => parallaxAnime(el, titleWorldTranslate), 10)) window.addEventListener('scroll', throttle(() => parallaxAnime(el, titleWorldTranslate), 10))
setTimeout(() => parallaxAnime(el, titleWorldTranslate), 50) requestAnimationFrame(() => parallaxAnime(el, titleWorldTranslate), 50)
}, },
onHidden: () => window.removeEventListener('scroll', parallaxAnime) onHidden: () => window.removeEventListener('scroll', parallaxAnime)
}) })

View File

@@ -10,7 +10,6 @@ export const animateIn = () => {
easing: 'easeOutQuart', easing: 'easeOutQuart',
duration: animDuration duration: animDuration
}) })
// Simple slide and fade on each part of the page // Simple slide and fade on each part of the page
tl.add({ tl.add({
targets: document.querySelectorAll('.page__part'), targets: document.querySelectorAll('.page__part'),

View File

@@ -38,7 +38,7 @@ export const animateIn = () => {
// Illustration // Illustration
tl.add({ tl.add({
targets: '.place__illustration', targets: '.place__illustration',
scale: [1.075, 1], scale: [1.1, 1],
opacity: [0, 1] opacity: [0, 1]
}, 0) }, 0)

View File

@@ -1,35 +1,38 @@
import anime from 'animejs' import anime from 'animejs'
import { animDuration } from 'utils/store' import { animDuration, animDelay } from 'utils/store'
/* /*
** Transition In ** Transition In
*/ */
export const animateIn = () => { export const animateIn = () => {
const viewer = document.querySelector('.viewer')
const tl = anime.timeline({ const tl = anime.timeline({
easing: 'easeOutQuart', easing: 'easeOutQuart',
duration: animDuration duration: animDuration,
}) delay: animDelay
// Buttons
tl.add({
targets: '.viewer__top p, .viewer__top .buttons a',
translateY: [-32, 0],
delay: anime.stagger(150, { start: 600 }),
}) })
// Carousel // Carousel
tl.add({ tl.add({
targets: '.viewer .carousel', targets: viewer.querySelector('.carousel'),
opacity: [0, 1], opacity: [0, 1],
translateY: window.innerWidth >= 768 ? [32, 0] : ['-33%', '-37%'] translateY: window.innerWidth >= 768 ? [32, 0] : ['-33%', '-37%'],
}, 300) complete: event => event.animatables[0].target.removeAttribute('style')
})
// Carousel: Number // Carousel: Number
tl.add({ tl.add({
targets: '.viewer .carousel__number_column', targets: viewer.querySelector('.counter'),
opacity: [0, 1], opacity: [0, 1],
marginTop: [24, 0], translateY: [window.innerWidth >= 768 ? -24 : 24, 0]
delay: anime.stagger(100) }, 0)
}, 450)
// Buttons
tl.add({
targets: viewer.querySelectorAll('.tip, .viewer__buttons a'),
translateY: [-32, 0],
opacity: [0, 1],
delay: anime.stagger(120),
}, 400)
} }

View File

@@ -8,9 +8,10 @@ let baseURL
const pages = [''] const pages = ['']
// Get routes and push it to array // Get routes and push it to array
const routesExclude = ['sitemap', 'index', 'location', 'viewer']
fs.readdirSync('./src/routes').forEach(file => { fs.readdirSync('./src/routes').forEach(file => {
const filename = file.split('.')[0] const filename = file.split('.')[0]
if (!file.startsWith('.') && !filename.startsWith('_') && ['sitemap', 'index', 'location', 'viewer'].indexOf(filename) === -1) { if (!file.startsWith('.') && !filename.startsWith('_') && routesExclude.indexOf(filename) === -1) {
pages.push(filename) pages.push(filename)
} }
}) })

View File

@@ -12,7 +12,10 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
will-change: transform;
&, * {
will-change: transform, opacity;
}
// Content // Content
&__loader { &__loader {
@@ -29,7 +32,6 @@
height: 100%; height: 100%;
background-color: $color-primary; background-color: $color-primary;
transform-origin: 50% 0; transform-origin: 50% 0;
will-change: transform;
} }
// Hidden // Hidden

View File

@@ -59,7 +59,6 @@ button {
letter-spacing: -2vw; letter-spacing: -2vw;
pointer-events: none; pointer-events: none;
user-select: none; user-select: none;
will-change: transform;
@include breakpoint (lg) { @include breakpoint (lg) {
font-size: pxVW(700); font-size: pxVW(700);
@@ -67,6 +66,10 @@ button {
@include breakpoint (1920px) { @include breakpoint (1920px) {
font-size: rem(900px); font-size: rem(900px);
} }
&, span {
will-change: transform, opacity;
}
} }
@@ -109,6 +112,9 @@ button {
margin-right: -8px; margin-right: -8px;
} }
} }
span, em {
will-change: transform;
}
// Bigger version // Bigger version
&--big { &--big {
@@ -189,7 +195,7 @@ button {
.style-caps { .style-caps {
font-family: $font-sans; font-family: $font-sans;
font-size: rem(14px); font-size: rem(12px);
color: $color-tertiary; color: $color-tertiary;
text-transform: uppercase; text-transform: uppercase;
letter-spacing: 1px; letter-spacing: 1px;
@@ -198,6 +204,10 @@ button {
&--transparent { &--transparent {
color: rgba($color-tertiary, 0.5); color: rgba($color-tertiary, 0.5);
} }
@include breakpoint (sm) {
font-size: rem(14px);
}
} }
.style-description { .style-description {

View File

@@ -14,7 +14,7 @@
cursor: pointer; cursor: pointer;
outline: none; outline: none;
transition: background-color 350ms $ease-quart; transition: background-color 350ms $ease-quart;
will-change: background-color; will-change: transform, opacity;
@include breakpoint (sm) { @include breakpoint (sm) {
width: 56px; width: 56px;
@@ -160,7 +160,7 @@
overflow: visible; overflow: visible;
background-color: rgba($color-lightpurple, 0.5); background-color: rgba($color-lightpurple, 0.5);
transition: background-color 150ms $ease-inout; transition: background-color 150ms $ease-inout;
will-change: background-color; will-change: transform, opacity;
// Icon // Icon
svg[fill] { svg[fill] {

View File

@@ -12,6 +12,10 @@
margin-right: 72px; margin-right: 72px;
} }
&, a * {
will-change: transform, opacity;
}
a { a {
position: relative; position: relative;
z-index: 2; z-index: 2;

View File

@@ -23,6 +23,7 @@
span { span {
display: block; display: block;
will-change: transform;
} }
} }
p { p {
@@ -80,6 +81,7 @@
display: block; display: block;
width: 100%; width: 100%;
height: auto; height: auto;
will-change: transform, opacity;
} }
// Overlay // Overlay
@@ -142,6 +144,7 @@
span { span {
display: block; display: block;
will-change: transform;
} }
@include breakpoint (sm) { @include breakpoint (sm) {

View File

@@ -1,7 +1,7 @@
// Carousel // Carousel
.carousel { .carousel {
background-color: $color-primary; background-color: $color-primary;
overflow: hidden; will-change: transform, opacity;
@include breakpoint (sm) { @include breakpoint (sm) {
overflow: visible; overflow: visible;
@@ -65,7 +65,7 @@
height: 100%; height: 100%;
transform: scale($scale); transform: scale($scale);
transition: transform $duration $ease-quart, opacity ($duration / 2) $ease-quart; transition: transform $duration $ease-quart, opacity ($duration / 2) $ease-quart;
will-change: transform, opacity, top, left; @extend %willchange;
// Active photo // Active photo
&.is-active { &.is-active {
@@ -134,6 +134,7 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
box-shadow: 0 pxVW(15) pxVW(60) rgba(#000, 0.3); box-shadow: 0 pxVW(15) pxVW(60) rgba(#000, 0.3);
@extend %willchange;
@include breakpoint (sm) { @include breakpoint (sm) {
border-radius: $radius; border-radius: $radius;
@@ -162,6 +163,11 @@
height: auto; height: auto;
} }
} }
// Performance
%willchange {
will-change: transform, opacity;
}
} }
@@ -231,11 +237,11 @@
left: 0; left: 0;
width: 100%; width: 100%;
opacity: 0; opacity: 0;
margin-top: 32px;
padding-bottom: 4px;
text-align: center; text-align: center;
transition: transform 0.9s $ease-quart, opacity 0.9s $ease-quart; transition: transform 0.9s $ease-quart, opacity 0.9s $ease-quart;
will-change: transform, opacity; will-change: transform, opacity;
margin-top: 32px;
padding-bottom: 4px;
@include breakpoint (sm) { @include breakpoint (sm) {
margin-top: pxVW(80); margin-top: pxVW(80);
@@ -244,6 +250,11 @@
margin-top: 72px; margin-top: 72px;
} }
// State
.state {
margin-top: 6px;
}
// States // States
&.is-prev { &.is-prev {
transform: translateY(-$distance); transform: translateY(-$distance);
@@ -255,11 +266,6 @@
&.is-next { &.is-next {
transform: translateY($distance); transform: translateY($distance);
} }
// State
.state {
margin-top: 6px;
}
} }

View File

@@ -8,6 +8,10 @@
overflow: hidden; overflow: hidden;
pointer-events: none; pointer-events: none;
&, * {
will-change: transform, opacity;
}
// Photo // Photo
&__image { &__image {
width: 100%; width: 100%;
@@ -17,7 +21,6 @@
transform: scale(1.1); transform: scale(1.1);
background: $color-primary; background: $color-primary;
transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart; transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart;
will-change: transform, opacity;
img { img {
position: relative; position: relative;
@@ -48,7 +51,6 @@
opacity: 0; opacity: 0;
transform: scale(1.1) translateY(24px); transform: scale(1.1) translateY(24px);
transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart; transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart;
will-change: transform, opacity;
// Visible state // Visible state
&.is-visible { &.is-visible {
@@ -74,7 +76,6 @@
background-color: $color-primary; background-color: $color-primary;
border-radius: 100%; border-radius: 100%;
transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart; transition: transform 0.8s $ease-quart, opacity 0.8s $ease-quart;
will-change: transform, opacity;
// Hidden state // Hidden state
&.is-hidden { &.is-hidden {

View File

@@ -92,6 +92,10 @@
margin-bottom: 200px; margin-bottom: 200px;
font-size: rem(248px); font-size: rem(248px);
} }
span {
will-change: transform;
}
} }
// Massive title // Massive title

View File

@@ -1,6 +1,11 @@
.page { .page {
overflow-x: hidden; overflow-x: hidden;
// Page part
&__part {
will-change: transform, opacity;
}
// Top part // Top part
&__top { &__top {
margin-top: 96px; margin-top: 96px;
@@ -64,7 +69,9 @@
margin-bottom: 40px; margin-bottom: 40px;
} }
dt { dt {
margin-bottom: 8px; @include breakpoint (sm) {
margin-bottom: 8px;
}
} }
} }

View File

@@ -78,6 +78,7 @@
padding-top: pxVW(200); padding-top: pxVW(200);
padding-bottom: 72px; padding-bottom: 72px;
background-color: $color-tertiary; background-color: $color-tertiary;
will-change: transform, opacity;
@include breakpoint (m) { @include breakpoint (m) {
padding-bottom: 96px; padding-bottom: 96px;
@@ -170,6 +171,7 @@
background-position: 0 0; background-position: 0 0;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% auto; background-size: 100% auto;
will-change: transform, opacity;
@include breakpoint (sm) { @include breakpoint (sm) {
background-image: var(--url-desktop); background-image: var(--url-desktop);

View File

@@ -3,6 +3,7 @@
position: relative; position: relative;
height: 100vh; height: 100vh;
min-height: 560px; min-height: 560px;
padding-top: 16px;
@include breakpoint (sm) { @include breakpoint (sm) {
width: 100%; width: 100%;
@@ -10,6 +11,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
padding-top: 24px;
} }
@@ -18,7 +20,6 @@
*/ */
&__top { &__top {
z-index: 10; z-index: 10;
margin-top: 16px;
padding-left: 24px; padding-left: 24px;
padding-right: 16px; padding-right: 16px;
display: flex; display: flex;
@@ -29,7 +30,7 @@
@include breakpoint (sm) { @include breakpoint (sm) {
// position: static; // position: static;
justify-content: center; justify-content: center;
margin: 24px 0; margin-bottom: 24px;
} }
// Tip message // Tip message

View File

@@ -29,7 +29,7 @@
// Scroll to page top // Scroll to page top
window.scrollTo(0,0) window.scrollTo(0,0)
// Run the page animation / after a tiny delay // Run the page animation / after a tiny delay
setTimeout(() => animateIn(scope), 1) requestAnimationFrame(() => animateIn(scope))
}, animDelayPanel) }, animDelayPanel)
}) })
</script> </script>