forked from davidjerleke/embla-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1999-99a21728ad9b58c2815c.js
2 lines (2 loc) · 1.83 KB
/
1999-99a21728ad9b58c2815c.js
1
2
"use strict";(self.webpackChunkembla_carousel_docs=self.webpackChunkembla_carousel_docs||[]).push([[1999],{1999:function(e,n,l){l.r(n),n.default="import { EmblaCarouselType } from 'embla-carousel'\n\nconst TWEEN_FACTOR = 1.2\n\nconst calculateTweenValuesParallax = (\n emblaApi: EmblaCarouselType\n): number[] => {\n const engine = emblaApi.internalEngine()\n const scrollProgress = emblaApi.scrollProgress()\n\n return emblaApi.scrollSnapList().map((scrollSnap, index) => {\n if (!emblaApi.slidesInView().includes(index)) return 0\n let diffToTarget = scrollSnap - scrollProgress\n\n if (engine.options.loop) {\n engine.slideLooper.loopPoints.forEach((loopItem) => {\n const target = loopItem.target()\n if (index === loopItem.index && target !== 0) {\n const sign = Math.sign(target)\n if (sign === -1) diffToTarget = scrollSnap - (1 + scrollProgress)\n if (sign === 1) diffToTarget = scrollSnap + (1 - scrollProgress)\n }\n })\n }\n return diffToTarget * (-1 / TWEEN_FACTOR) * 100\n })\n}\n\nexport const setupTweenParallax = (\n emblaApi: EmblaCarouselType\n): {\n applyTweenParallax: () => void\n removeTweenParallax: () => void\n} => {\n const tweenNodes = <HTMLElement[]>(\n emblaApi\n .slideNodes()\n .map((slideNode) => slideNode.querySelector('.embla__parallax__layer'))\n )\n\n const applyTweenParallax = (): void => {\n const tweenValues = calculateTweenValuesParallax(emblaApi)\n tweenValues.forEach((tweenValue, index) => {\n tweenNodes[index].style.transform = `translateX(${tweenValue}%`\n })\n }\n\n const removeTweenParallax = (): void => {\n tweenNodes.forEach((slide) => slide.removeAttribute('style'))\n }\n\n return {\n applyTweenParallax,\n removeTweenParallax\n }\n}\n"}}]);
//# sourceMappingURL=1999-99a21728ad9b58c2815c.js.map