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

Class Slideshow

src/js/demo2/slideshow.js:5–164  ·  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: 'inset(10% 30.1% 0% 30% round 25vw 25vw 0vw 0vw)', //two equal values cause problems because browser uses shorthand
20 final: 'inset(15% 40.1% 15% 40% round 25vw 25vw 25.01vw 25.01vw)',
21 hover: 'inset(20% 40% 20.01% 40.01% round 25vw 25vw 25.01vw 25.01vw)'
22 }
23 };
24
25 this.init();
26 }
27 init() {
28 this.DOM.slides[this.current].classList.add('slide--current');
29 gsap.set(this.slides[this.current].DOM.imgWrap, {clipPath: this.config.clipPath.initial});
30
31 for (const slide of this.slides) {
32 slide.DOM.link.addEventListener('mouseenter', () => {
33 gsap.killTweensOf(slide.DOM.imgWrap);
34 gsap.to(slide.DOM.imgWrap, {
35 duration: 0.7,
36 ease: 'expo',
37 clipPath: this.config.clipPath.hover
38 });
39 });
40 slide.DOM.link.addEventListener('mouseleave', () => {
41 gsap.killTweensOf(slide.DOM.imgWrap);
42 gsap.to(slide.DOM.imgWrap, {
43 duration: 0.7,
44 ease: 'expo',
45 clipPath: this.config.clipPath.initial
46 });
47 });
48 }
49 }
50 next() {
51 this.navigate('next');
52 }
53 prev() {
54 this.navigate('prev');
55 }
56 navigate(direction) {
57 if ( this.isAnimating ) {
58 return false;
59 }
60 this.isAnimating = true;
61
62 const currentSlide = this.slides[this.current];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected