Create reveal animation for About page Purpose section
Using Motion One inView for detecting and toggling class 🤌
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, afterUpdate } from 'svelte'
|
import { onMount, afterUpdate } from 'svelte'
|
||||||
import { map } from '$utils/functions'
|
import { map } from '$utils/functions'
|
||||||
import { scroll, animate, type ScrollOptions } from 'motion'
|
import { scroll, animate, inView, type ScrollOptions } from 'motion'
|
||||||
// Components
|
// Components
|
||||||
import Metas from '$components/Metas.svelte'
|
import Metas from '$components/Metas.svelte'
|
||||||
import PageTransition from '$components/PageTransition.svelte'
|
import PageTransition from '$components/PageTransition.svelte'
|
||||||
@@ -22,10 +22,10 @@
|
|||||||
// console.log(data)
|
// console.log(data)
|
||||||
|
|
||||||
let scrollY: number, innerWidth: number, innerHeight: number
|
let scrollY: number, innerWidth: number, innerHeight: number
|
||||||
|
let purposeEl: HTMLElement
|
||||||
let stepsEl: HTMLElement
|
let stepsEl: HTMLElement
|
||||||
let photosGridEl: HTMLElement
|
let photosGridEl: HTMLElement
|
||||||
let photosGridOffset: number = photosGridEl && photosGridEl.offsetTop
|
let photosGridOffset: number = photosGridEl && photosGridEl.offsetTop
|
||||||
let sectionsObserver: IntersectionObserver
|
|
||||||
|
|
||||||
$: parallaxPhotos = photosGridEl && map(scrollY, photosGridOffset - innerHeight, photosGridOffset + innerHeight / 1.5, 0, innerHeight * 0.15, true)
|
$: parallaxPhotos = photosGridEl && map(scrollY, photosGridOffset - innerHeight, photosGridOffset + innerHeight / 1.5, 0, innerHeight * 0.15, true)
|
||||||
$: fadedPhotosIndexes = innerWidth > 768
|
$: fadedPhotosIndexes = innerWidth > 768
|
||||||
@@ -33,24 +33,17 @@
|
|||||||
: [0]
|
: [0]
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Sections observer
|
/**
|
||||||
sectionsObserver = new IntersectionObserver(([{ isIntersecting, target }]: [IntersectionObserverEntry] & [{ target: HTMLElement }]) => {
|
* Purpose reveal
|
||||||
|
*/
|
||||||
|
inView(purposeEl, ({ target, isIntersecting }) => {
|
||||||
target.classList.toggle('is-visible', isIntersecting)
|
target.classList.toggle('is-visible', isIntersecting)
|
||||||
|
}, { amount: 0.75 })
|
||||||
// Run effect once
|
|
||||||
if (isIntersecting && target.dataset.stay) {
|
|
||||||
sectionsObserver.unobserve(target)
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
threshold: 0.5,
|
|
||||||
rootMargin: '0% 0px 0%'
|
|
||||||
})
|
|
||||||
|
|
||||||
const sections = document.querySelectorAll('.about [data-part]')
|
|
||||||
sections.forEach(section => sectionsObserver.observe(section))
|
|
||||||
|
|
||||||
|
|
||||||
// Steps scroll animation
|
/**
|
||||||
|
* Steps scroll animation
|
||||||
|
*/
|
||||||
const cards = stepsEl.querySelectorAll('.step')
|
const cards = stepsEl.querySelectorAll('.step')
|
||||||
const cardsAmount = data.process_steps.length
|
const cardsAmount = data.process_steps.length
|
||||||
|
|
||||||
@@ -73,12 +66,6 @@
|
|||||||
opacity: [0, 0.2 + (0.05 * reverseIndex)]
|
opacity: [0, 0.2 + (0.05 * reverseIndex)]
|
||||||
}), scrollOptions)
|
}), scrollOptions)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Destroy
|
|
||||||
return () => {
|
|
||||||
sectionsObserver && sectionsObserver.disconnect()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +89,7 @@
|
|||||||
text={data.description}
|
text={data.description}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<section class="about__purpose" data-part data-stay="true">
|
<section class="about__purpose" bind:this={purposeEl}>
|
||||||
<div class="container-wide">
|
<div class="container-wide">
|
||||||
<div class="text title-xl" role="heading">
|
<div class="text title-xl" role="heading">
|
||||||
{@html data.purpose_text}
|
{@html data.purpose_text}
|
||||||
|
|||||||
@@ -3,18 +3,16 @@
|
|||||||
** Purpose
|
** Purpose
|
||||||
*/
|
*/
|
||||||
&__purpose {
|
&__purpose {
|
||||||
position: relative;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
.container-wide {
|
.container-wide {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
overflow: hidden;
|
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
min-height: calc(100vh - var(--sides));
|
min-height: calc(100vh - var(--sides));
|
||||||
color: #fff;
|
color: #fff;
|
||||||
padding: 0 8%;
|
padding: 0 8%;
|
||||||
border-radius: 16px;
|
|
||||||
|
|
||||||
@include bp (sm) {
|
@include bp (sm) {
|
||||||
padding: 0 18%;
|
padding: 0 18%;
|
||||||
@@ -23,11 +21,13 @@
|
|||||||
|
|
||||||
// Text
|
// Text
|
||||||
.text {
|
.text {
|
||||||
|
opacity: 0.2;
|
||||||
max-width: 1024px;
|
max-width: 1024px;
|
||||||
|
transition: opacity 3s var(--ease-quart);
|
||||||
|
|
||||||
:global(strong) {
|
:global(strong) {
|
||||||
color: $color-secondary-light;
|
|
||||||
font-weight: inherit;
|
font-weight: inherit;
|
||||||
|
transition: color 3s var(--ease-quart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,14 +41,31 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
background-color: $color-primary-tertiary20;
|
background-color: $color-primary-tertiary20;
|
||||||
transition: opacity 1.2s var(--ease-quart);
|
border-radius: 8px;
|
||||||
|
transform: scale(1.15) translateZ(0);
|
||||||
|
transition-property: opacity, transform;
|
||||||
|
transition-duration: 3s;
|
||||||
|
transition-timing-function: var(--ease-quart);
|
||||||
|
transition-delay: 0.25s;
|
||||||
|
|
||||||
|
@include bp (sm) {
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Visible state
|
// Visible state
|
||||||
&:global(.is-visible) {
|
&:global(.is-visible) {
|
||||||
|
.text {
|
||||||
|
opacity: 1;
|
||||||
|
|
||||||
|
:global(strong) {
|
||||||
|
color: $color-secondary-light;
|
||||||
|
}
|
||||||
|
}
|
||||||
.background {
|
.background {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
transform: scale(1) translateZ(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user