Created
February 25, 2021 12:54
-
-
Save pigeonfresh/7adefc50a563ce0e6a7d4eebebc9cead to your computer and use it in GitHub Desktop.
Parallax Visual Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[data-component="visual"] { | |
overflow: hidden; | |
position: relative; | |
@include aspect-ratio(16, 9); | |
picture { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
} | |
img { | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
object-position: center; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { gsap } from 'gsap'; | |
import ScrollTrigger from 'gsap/ScrollTrigger'; | |
import AbstractComponent from '../AbstractComponent'; | |
gsap.registerPlugin(ScrollTrigger); | |
export default class Visual extends AbstractComponent { | |
public static readonly displayName: string = 'visual'; | |
private static readonly offset: number = 200; | |
private picture: HTMLPictureElement | null = this.getElement('picture'); | |
constructor(el: HTMLElement) { | |
super(el); | |
this.createParallaxFX(); | |
} | |
private createParallaxFX = () => { | |
if (!this.picture) return; | |
const offset = Visual.offset; | |
this.picture.style.bottom = `-${offset}px`; | |
ScrollTrigger.create({ | |
trigger: this.picture, | |
scrub: 1, | |
animation: gsap.to(this.picture, { | |
y: -offset, | |
}) | |
}) | |
}; | |
public dispose() { | |
// | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment