Infinite scrolling carousel with hover effects using Framer Motion

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 63

  • @Akios281
    @Akios281 9 หลายเดือนก่อน +5

    I had been trying to do this for weeks with Framer Motion using a different approach, but I wasn’t as satisfied. Thank you for this great tutorial. I’m learning a lot by following you. I prefer this video format focused on a replicable component that can easily adapt to various situations over the lengthy clone videos.

    • @builtwithcode
      @builtwithcode  9 หลายเดือนก่อน +1

      Glad to hear you’re finding value from the videos! And thanks for the feedback on the video lengths, I’ll continue to focus on more narrow tutorials but may experiment with a longer build in the future.

  • @spillttea3195
    @spillttea3195 6 หลายเดือนก่อน +1

    Bro I was trying to do this for so long but you were the only one who explained it properly! thanks so much for the video !

  • @aleaus
    @aleaus 7 หลายเดือนก่อน +9

    To eliminate the jump give the motion.div a width: max-content

    • @kosti2647
      @kosti2647 7 หลายเดือนก่อน +1

      exactly! otherwise it might have width capped by the end of the viewport

    • @meirbek241
      @meirbek241 7 หลายเดือนก่อน +1

      thank you

    • @sglza
      @sglza 28 วันที่ผ่านมา

      I actually don't get how he got it to work without this

  • @jasiekhalczuk4974
    @jasiekhalczuk4974 2 หลายเดือนก่อน

    best framer-motion carousel tutorial, blessing

  • @NotWasim
    @NotWasim 2 หลายเดือนก่อน

    This is class. Made it super simple to understand what everything is!

  • @8bitWatermelon
    @8bitWatermelon 10 หลายเดือนก่อน

    back with a banger ⚡🧪💯

  • @scrumptious1177
    @scrumptious1177 10 หลายเดือนก่อน

    You just saved my day! Thank you!

    • @builtwithcode
      @builtwithcode  9 หลายเดือนก่อน

      Glad I could help!

  • @alexandrebtn
    @alexandrebtn 2 หลายเดือนก่อน

    Thanks a lot for this video !

  • @ricardocnn
    @ricardocnn 6 หลายเดือนก่อน

    Wow! Super Top!

  • @DazzyDude00
    @DazzyDude00 5 หลายเดือนก่อน +1

    Didn't really need to use a 3rd party package to get the size of the div container, could've used `scrollWidth` to get that value

  • @faisalrehman3868
    @faisalrehman3868 6 หลายเดือนก่อน +1

    after 25 sec of duration it give a jerk and restart from the 1st image that looks wired if you decrease duration to less i.e 5. is there any fix for this thing ?

  • @cx20012002
    @cx20012002 7 หลายเดือนก่อน

    great video, just 1 quick question, what is that rerender state for? I can't see anywhere using this state apart from setting it true or false, I removed it and everything is still working fine, is it just for triggering useEffect to rerender the component? I think mustFinish state is enough to trigger, please let me know if i am wrong.
    also duration * (1 - xTranslation.get() / finalPosition) seems to be unnecessary, just use duration and can't tell the difference

    • @builtwithcode
      @builtwithcode  7 หลายเดือนก่อน

      Yep the rerender variable wasn't really necessary :)
      On the duration piece - you need the custom version when mustFinish is true, because the default duration lengths correspond to the time it takes to scroll the entire row. By definition if mustFinish is true, we have already progressed part way through the row of cards, so we need to scale the duration to get the correct intended speed.

  • @doskooza
    @doskooza 5 หลายเดือนก่อน

    Awesome! Thanks

  • @raimondszakis8337
    @raimondszakis8337 4 หลายเดือนก่อน +1

    I used this as example for my infinite vertical carousel, I am having issue where complete callback is never called despite animation running in loops, this in turn causes issue when onDrag Y pos is updated, I end up creating control version where Y pos is not different after animation has finished looping once :D quite funny, I'll try to sort that on my own
    ----update
    Fun fact, onRepeat callback is not implemented, it only exists as part of .d.ts file as interface value.
    I fixed my issue by manually detecting when I am close to finishing single iteration via onUpdate callback, and seting mustFinish(false)

  • @ChampuStrike
    @ChampuStrike 3 หลายเดือนก่อน

    I been trying to replicate the same but i get snaps back to the begining instead of it reseting in the background, what am i doing wrong?

  • @bhagyeshpatel6472
    @bhagyeshpatel6472 7 หลายเดือนก่อน

    Great 🎉 very helpful , Just one question can we change animation direction from left to right.?

  • @alejita.jaramillo
    @alejita.jaramillo 3 หลายเดือนก่อน

    nice guide... but if mouseover the picture how can set paused and after mouseout retake the animation keeps on the moving from the same point without restart the animation... I would really appreciate it if you could help me

    • @useMadness
      @useMadness 3 หลายเดือนก่อน

      I used a trick by setting the FAST_DURATION variable to a really big number (100,000) to make it seem like it’s paused. It still moves, but super slowly, so it looks like it’s on pause. If you come up with a better way to do this, that would be great

  • @elenbrodt3880
    @elenbrodt3880 2 หลายเดือนก่อน

    when it gets in the end of the second array, it its with a black spot, how can i fix it?

  • @ashn_427
    @ashn_427 6 หลายเดือนก่อน

    Can the slowdown on hover effect be done using only javascript? If so can someone please reply with a link to any video explaining how it's done?

  • @mikescriven
    @mikescriven 7 หลายเดือนก่อน +1

    Great video!
    This causes a horizontal scrollbar to show up on my website, can anyone help me remove it?
    Any help would be greatly appreciated.

    • @builtwithcode
      @builtwithcode  7 หลายเดือนก่อน

      In CSS, you can use the ::-webkit-scrollbar:horizontal selector and set the width/height to 0 & background to transparent. If you want an example, I do this for a vertical scrollbar towards the end of my custom scrollbar video.

    • @ThomasAndreLubin
      @ThomasAndreLubin หลายเดือนก่อน

      Is there other way to solve that ? ::-webkit-scrollbar is non standard and not recommended in production

  • @harshitpant07
    @harshitpant07 5 หลายเดือนก่อน

    loved the approach i was trying to do the same but I am stuck on a problem if the content increases let's say card's data from a API the speed increases how do we decrease speed proportionally to content

    • @builtwithcode
      @builtwithcode  5 หลายเดือนก่อน

      Instead of using a fixed value for the duration, you can make it dynamic based on the length of the response array. E.g., something like duration = arrayLength * 10 (the 10 will control the speed which you can play around with)

  • @andrewii23
    @andrewii23 10 หลายเดือนก่อน +3

    Gem hidden here

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 4 หลายเดือนก่อน

    Thank you so much

  • @alexandertarariko1572
    @alexandertarariko1572 8 หลายเดือนก่อน

    Awesome, ty

  • @mankaransingh1029
    @mankaransingh1029 6 หลายเดือนก่อน

    Great Video! Just want to ask can I reverse the direction? Can anyone help me with the code

  • @Forsvinne77
    @Forsvinne77 8 หลายเดือนก่อน

    Thanks ❤

  • @8bitWatermelon
    @8bitWatermelon 10 หลายเดือนก่อน

    [QUESTION]: Why the use of the pages directory? Is there a particular reason or just preference.

    • @builtwithcode
      @builtwithcode  10 หลายเดือนก่อน +2

      I'm sticking with the Pages Router for now because Framer Motion has issues with the App Router, particularly around and page transitions. But I think this specific project *should* work fine in the App Router.

    • @Dexquest3d
      @Dexquest3d 10 หลายเดือนก่อน

      I'll try this on the app router

    • @kuizigames1872
      @kuizigames1872 9 หลายเดือนก่อน

      @@Dexquest3d Did you manage to try this on routed? I am unable to get the infinite scrolling to start.

  • @OutrospectiveOfficial
    @OutrospectiveOfficial 9 หลายเดือนก่อน +1

    There's still a slight occasional jump in the scrolling behaviour when the reset of the scrolling items happens.
    Did you figure out what's causing this by any chance?

    • @n59k.
      @n59k. 9 หลายเดือนก่อน

      same problem(

    • @meirbek241
      @meirbek241 7 หลายเดือนก่อน

      same issue, please tag me if you find an answer

    • @n59kk
      @n59kk 7 หลายเดือนก่อน

      @@meirbek241i just solved it by creating a similar animation with tailwind without frame motion

    • @meirbek241
      @meirbek241 7 หลายเดือนก่อน

      @@n59kk interesting, do you mind sharing link to repo how you solved it?

  • @salmaahmed7789
    @salmaahmed7789 6 หลายเดือนก่อน

    it waits for the last item to reach the end and then reset and start the loop which leaves a lot of space, I don't understand why

    • @builtwithcode
      @builtwithcode  6 หลายเดือนก่อน

      Did you map over two copies of the card array?

    • @zh1094
      @zh1094 4 หลายเดือนก่อน

      it's because the formula he used, won't work for you as it is.

  • @laurensmesure
    @laurensmesure 8 หลายเดือนก่อน

    Great video, thanks! Not entirely sure about the last part. I have refactored it with an `isSlow` state value and the useEffect like this:
    ```
    useEffect(() => {
    if (!width) return;
    const finalPosition = -width / 2 - 16;
    const controls = animate(xTranslation, [xTranslation.get(), finalPosition], {
    ease: "linear",
    duration: (isSlow ? 120 : 60) * (1 - xTranslation.get() / finalPosition),
    repeat: Infinity,
    repeatType: "loop",
    repeatDelay: 0,
    });
    return () => {
    controls.stop();
    };
    }, [width, xTranslation, isSlow]);
    ```
    Was there a bug that made you implement the useEffect with `mustFinish` & `rerender`?

    • @builtwithcode
      @builtwithcode  8 หลายเดือนก่อน

      I probably didn't need `rerender` :). But I needed `mustFinish` to know whether to set the xTranslation animation to start at 0 (reshift everything back to the starting point) or to xTranslation.get() (handle changes in speed). Looking at your code, I don't see a place to reset the value of xTranslation to 0, so not sure if this would work. But let me know if I'm missing something.

    • @laurensmesure
      @laurensmesure 8 หลายเดือนก่อน +3

      @@builtwithcode Yes you're right, good catch. I refactored it and set the `speed` attribute.
      ```
      const control = useRef(null!);
      useEffect(() => {
      if (!width) return;
      const finalPosition = -width / 2 - 16;
      control.current = animate(xTranslation, [0, finalPosition], {
      ease: "linear",
      duration: 60,
      repeat: Infinity,
      repeatType: "loop",
      repeatDelay: 0,
      });
      return () => {
      control.current.stop();
      };
      }, [width, xTranslation]);
      ...
      onPointerDown={() => control.current.speed = 0.5}
      ```

  • @zh1094
    @zh1094 4 หลายเดือนก่อน

    I am a bit disappointed that the formula wasn't explained properly at all because the exact final position formula will not work for everyone.

    • @builtwithcode
      @builtwithcode  4 หลายเดือนก่อน

      Sorry to hear that, is there anything I can clarify?

    • @Hellothere-by4ye
      @Hellothere-by4ye 2 หลายเดือนก่อน

      remove left and right padding if their is any on scroll container

  • @SubhamayPaul
    @SubhamayPaul 9 หลายเดือนก่อน

    Can you provide the entire code?

    • @builtwithcode
      @builtwithcode  9 หลายเดือนก่อน

      GitHub repo link is in the description, the main branch has the final code

  • @shoumyadeepnarayan1739
    @shoumyadeepnarayan1739 8 หลายเดือนก่อน

    where is the logic for resetting the image container content ??

    • @builtwithcode
      @builtwithcode  8 หลายเดือนก่อน

      This works through the "infinite" animation and smartly selecting the endpoint for the xTranslation to line up the second copy of the cards with the original starting position.

  • @n59k.
    @n59k. 9 หลายเดือนก่อน +1

    thx 4 vid!
    i have the problem with undefined reading resolver in controls.stop, so i used this method to handle the problem.
    👇
    const stopAnimation = () => {
    if (controls) {
    controls.stop();
    }
    };
    return stopAnimation;

    • @luiscosta2385
      @luiscosta2385 9 หลายเดือนก่อน

      Where did you put this one?

    • @n59k.
      @n59k. 9 หลายเดือนก่อน

      @@luiscosta2385 to the same place where he writes return controls.stop

    • @safiye430
      @safiye430 8 หลายเดือนก่อน

      perfect! you saved my day, thanks