MCPcopy Create free account
hub / github.com/codrops/ShapesSlideshow / Slideshow

Class Slideshow

src/js/demo3/slideshow.js:5–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import { gsap } from 'gsap';
4
5export class Slideshow extends EventEmitter {
6 constructor(el) {
7 super();
8 this.DOM = {el};
9
10 this.DOM.slides = [...this.DOM.el.querySelectorAll('.slide')];
11 this.slides = [];
12 this.DOM.slides.forEach(slide => this.slides.push(new Slide(slide)));
13 this.slidesTotal = this.slides.length;
14
15 this.current = 0;
16
17 this.config = {
18 clipPath: {
19 initial: 'polygon(100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%, 0% 0%)',
20 final: {
21 right: 'polygon(75% 10%, 90% 50%, 75% 90%, 10% 90%, 20% 50%, 10% 10%)',
22 left: 'polygon(90% 10%, 75% 50%, 90% 90%, 30% 90%, 10% 50%, 30% 10%)'
23 },
24 hover: 'polygon(97% 10%, 97% 50%, 97% 87%, 3% 87%, 3% 50%, 3% 10%)'
25 }
26 };
27
28 this.init();
29 }
30 init() {
31 this.DOM.slides[this.current].classList.add('slide--current');
32 gsap.set(this.slides[this.current].DOM.imgWrap, {clipPath: this.config.clipPath.initial});
33
34 for (const slide of this.slides) {
35 slide.DOM.link.addEventListener('mouseenter', () => {
36 gsap.killTweensOf(slide.DOM.imgWrap);
37 gsap.to(slide.DOM.imgWrap, {
38 duration: 1,
39 ease: 'expo',
40 clipPath: this.config.clipPath.hover
41 });
42 });
43 slide.DOM.link.addEventListener('mouseleave', () => {
44 gsap.killTweensOf(slide.DOM.imgWrap);
45 gsap.to(slide.DOM.imgWrap, {
46 duration: 1,
47 ease: 'expo',
48 clipPath: this.config.clipPath.initial
49 });
50 });
51 }
52 }
53 next() {
54 this.navigate('next');
55 }
56 prev() {
57 this.navigate('prev');
58 }
59 navigate(direction) {
60 if ( this.isAnimating ) {
61 return false;
62 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected