-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
3878-804089a07e445489906f.js
2 lines (2 loc) · 2.42 KB
/
3878-804089a07e445489906f.js
1
2
"use strict";(self.webpackChunkembla_carousel_docs=self.webpackChunkembla_carousel_docs||[]).push([[3878],{3878:function(e,n,l){l.r(n),n.default="import { EmblaCarouselType, EmblaEventType } from 'embla-carousel'\n\nconst TWEEN_FACTOR_BASE = 0.2\nlet tweenFactor = 0\nlet tweenNodes: HTMLElement[] = []\n\nconst setTweenNodes = (emblaApi: EmblaCarouselType): void => {\n tweenNodes = emblaApi.slideNodes().map((slideNode) => {\n return slideNode.querySelector('.embla__parallax__layer') as HTMLElement\n })\n}\n\nconst setTweenFactor = (emblaApi: EmblaCarouselType): void => {\n tweenFactor = TWEEN_FACTOR_BASE * emblaApi.scrollSnapList().length\n}\n\nconst tweenParallax = (\n emblaApi: EmblaCarouselType,\n eventName?: EmblaEventType\n): void => {\n const engine = emblaApi.internalEngine()\n const scrollProgress = emblaApi.scrollProgress()\n const slidesInView = emblaApi.slidesInView()\n const isScrollEvent = eventName === 'scroll'\n\n emblaApi.scrollSnapList().forEach((scrollSnap, snapIndex) => {\n let diffToTarget = scrollSnap - scrollProgress\n const slidesInSnap = engine.slideRegistry[snapIndex]\n\n slidesInSnap.forEach((slideIndex) => {\n if (isScrollEvent && !slidesInView.includes(slideIndex)) return\n\n if (engine.options.loop) {\n engine.slideLooper.loopPoints.forEach((loopItem) => {\n const target = loopItem.target()\n\n if (slideIndex === loopItem.index && target !== 0) {\n const sign = Math.sign(target)\n\n if (sign === -1) {\n diffToTarget = scrollSnap - (1 + scrollProgress)\n }\n if (sign === 1) {\n diffToTarget = scrollSnap + (1 - scrollProgress)\n }\n }\n })\n }\n\n const translate = diffToTarget * (-1 * tweenFactor) * 100\n const tweenNode = tweenNodes[slideIndex]\n tweenNode.style.transform = `translateX(${translate}%)`\n })\n })\n}\n\nexport const setupTweenParallax = (\n emblaApi: EmblaCarouselType\n): (() => void) => {\n setTweenNodes(emblaApi)\n setTweenFactor(emblaApi)\n tweenParallax(emblaApi)\n\n emblaApi\n .on('reInit', setTweenNodes)\n .on('reInit', setTweenFactor)\n .on('reInit', tweenParallax)\n .on('scroll', tweenParallax)\n .on('slideFocus', tweenParallax)\n\n return (): void => {\n tweenNodes.forEach((slide) => slide.removeAttribute('style'))\n }\n}\n"}}]);
//# sourceMappingURL=3878-804089a07e445489906f.js.map