-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
1288-0ffb5fa2c43a81347539.js
2 lines (2 loc) · 2.55 KB
/
1288-0ffb5fa2c43a81347539.js
1
2
"use strict";(self.webpackChunkembla_carousel_docs=self.webpackChunkembla_carousel_docs||[]).push([[1288],{1288:function(e,n,s){s.r(n),n.default="\nconst TWEEN_FACTOR_BASE = 0.2;\nlet tweenFactor = 0;\nlet tweenNodes = [];\n\nconst setTweenNodes = (emblaApi) => {\n tweenNodes = emblaApi.slideNodes().map((slideNode) => {\n return slideNode.querySelector('.embla__parallax__layer');\n });\n};\n\nconst setTweenFactor = (emblaApi) => {\n tweenFactor = TWEEN_FACTOR_BASE * emblaApi.scrollSnapList().length;\n};\n\nconst tweenParallax = (emblaApi, eventName) => {\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))\n 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 = (emblaApi) => {\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 () => {\n tweenNodes.forEach((slide) => slide.removeAttribute('style'));\n };\n};\n"}}]);
//# sourceMappingURL=1288-0ffb5fa2c43a81347539.js.map