Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vuolen committed Aug 26, 2024
1 parent 3aa0893 commit 3b8e574
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ const wrappedDistance = (a: number, b: number) => {

const setOpacity = (emblaApi: EmblaCarouselType) => {
const slideNodes = emblaApi.slideNodes();
const slidesInView = slideNodes.map((_, index) => index);

const currentPosition = emblaApi.scrollProgress();

slidesInView.forEach((slideIndex) => {
slideNodes.forEach((_, slideIndex) => {
const slidePosition = emblaApi.scrollSnapList()[slideIndex];
const opacity = clamp(
1 - wrappedDistance(slidePosition, currentPosition) * 8.4,
Expand All @@ -47,10 +46,9 @@ const Carousel: React.FC<PropType> = ({ slides, options }) => {

useEffect(() => {
if (!emblaApi) return;

setOpacity(emblaApi);
emblaApi.on("reInit", setOpacity).on("scroll", setOpacity);

}, [emblaApi]);

return (
Expand Down

0 comments on commit 3b8e574

Please sign in to comment.