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

Class Slideshow

src/js/demo1/slideshow.js:5–171  ·  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 // the main wrapper <div class="slideshow">
9 this.DOM = {el};
10 // the slides
11 this.DOM.slides = [...this.DOM.el.querySelectorAll('.slide')];
12 // array of Slide obj instances
13 this.slides = [];
14 this.DOM.slides.forEach(slide => this.slides.push(new Slide(slide)));
15 // total number of Slides
16 this.slidesTotal = this.slides.length;
17 // current position
18 this.current = 0;
19 // some settings, like the clip paths
20 this.config = {
21 clipPath: {
22 initial: 'circle(55% at 70% 50%)',
23 final: 'circle(15% at 70% 50%)',
24 hover: 'circle(20% at 30% 50%)'
25 }
26 };
27 this.init();
28 }
29 init() {
30 // start with the first slide as the current slide
31 this.DOM.slides[this.current].classList.add('slide--current');
32 // set the initial clip path
33 gsap.set(this.slides[this.current].DOM.imgWrap, {clipPath: this.config.clipPath.initial});
34 // when hovering over the "explore" link on each slide, we animate the clip path from this.config.clipPath.initial to this.config.clipPath.hover
35 for (const slide of this.slides) {
36 slide.DOM.link.addEventListener('mouseenter', () => {
37 gsap.killTweensOf(slide.DOM.imgWrap);
38 gsap.to(slide.DOM.imgWrap, {
39 duration: 1,
40 ease: 'expo',
41 clipPath: this.config.clipPath.hover
42 });
43 });
44 slide.DOM.link.addEventListener('mouseleave', () => {
45 gsap.killTweensOf(slide.DOM.imgWrap);
46 gsap.to(slide.DOM.imgWrap, {
47 duration: 1,
48 ease: 'expo',
49 clipPath: this.config.clipPath.initial
50 });
51 });
52 }
53 }
54 // navigate to the next slide
55 next() {
56 this.navigate('next');
57 }
58 // navigate to the previous slide
59 prev() {
60 this.navigate('prev');
61 }
62 navigate(direction) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected