Create an infinite horizontal scroll animation

Sdílet
Vložit
  • čas přidán 6. 07. 2024
  • 🎓 Did you know I have courses? Both free and premium ones: kevinpowell.co/courses?...
    Infinite scroll animations for things like logos are relatively common these days, but there is a lot that we can do incorrectly when making one, so I decided to try and make one that respects prefers-reduced-motion, and is progressively enhanced with just a couple of lines of JS to add in the functionality (and duplicate content that we’ll need).
    🔗 Links
    ✅ The code from this video: codepen.io/kevinpowell/pen/Ba...
    ✅ My playlist on CSS masks: • CSS Masks
    ⌚ Timestamps
    00:00 - Introduction
    01:16 - The HTML
    02:23 - Basic CSS
    05:31 - Checking for prefers-reduced-motion with JavaScript
    08:50 - Setting the stage for the animation with CSS
    13:16 - Adding the animation
    19:53 - Fixing the doubled content in the HTML
    25:50 - Adding speed and direction options
    #css
    --
    Come hang out with other dev's in my Discord Community
    💬 / discord
    Keep up to date with everything I'm up to
    ✉ www.kevinpowell.co/newsletter
    Come hang out with me live every Monday on Twitch!
    📺 / kevinpowellcss
    ---
    Help support my channel
    👨‍🎓 Get a course: www.kevinpowell.co/courses
    👕 Buy a shirt: teespring.com/stores/making-t...
    💖 Support me on Patreon: / kevinpowell
    ---
    My editor: VS Code - code.visualstudio.com/
    ---
    I'm on some other places on the internet too!
    If you'd like a behind the scenes and previews of what's coming up on my CZcams channel, make sure to follow me on Instagram and Twitter.
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell
    ---
    And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!

Komentáře • 272

  • @Aliena92
    @Aliena92 Před 3 měsíci +9

    "I help people fall deeply, madly in in love with css." You're succeeding every time! Thank you for all these gems!

  • @Shaheer-xs5os
    @Shaheer-xs5os Před 9 měsíci +54

    80% of my CSS skills, I have learned from you Kevin, you're the best buddy, thank you for these amzing videos ☺

    • @user-tc5do1ps9p
      @user-tc5do1ps9p Před 2 měsíci

      Same

    • @Catalyph
      @Catalyph Před 2 měsíci

      LOL 80% of my CSS skills i have learn from THIS video!😂

  • @MarshallSC1
    @MarshallSC1 Před 9 měsíci +4

    I know You don't do a lot of JS video, but man, when you do, they are beyond awesome.
    Thank You for the free knowledge!

  • @e11world
    @e11world Před 6 měsíci +1

    I love the way you setup things and how you explain it so well even in JS. Thank you for these videos as always!

  • @lucacarrara00
    @lucacarrara00 Před 9 měsíci +5

    I was just looking for this kind of animation yesterday, found few solutions but neither of them with an explanation. Now I got the idea behind it and also the reason why my infinite scroll had this kind of "jump" between the first set of icons and the second. Thanks a lot!

  • @kerrykreiter445
    @kerrykreiter445 Před 9 měsíci

    Probably my favorite of all your videos I’ve seen. Thank you for sharing this incredibly useful content!! Kevin, you’re the best!

  • @rtindevelops7580
    @rtindevelops7580 Před 12 dny

    Kevin, you make me fall in love with CSS each time, I visit one of your videos . thank you so much for the value! 🙌

  • @yaseen2002
    @yaseen2002 Před 9 měsíci

    Hey Kevin you are a star. This logo animation was exactly what I needed for my current project. I didn't know where to begin until I saw your CZcams video. Thank you one more.

  • @naveenvenkateshk
    @naveenvenkateshk Před 9 měsíci +1

    Thank you Kevin for this informative video. 2 years ago I had a requirement to implement an infinite scroll component to display brand logos. I searched in internet and youtube but never found a proper guide / implementation. If I had this video 2 years ago, it would have saved me a ton of efforts, time and stress.

  • @anchimayen
    @anchimayen Před 9 měsíci +53

    Couldn't be a more perfect timing for me. I've been thinking about adding such a slider to my art portfolio website. Appreciate your work man! ✨

    • @webrevolution.
      @webrevolution. Před 9 měsíci

      Man? How dare you assume his gender?!!?!?!
      Lmao. Just kidding. Totally agree.

    • @Sunny-Gupta1
      @Sunny-Gupta1 Před 9 měsíci

      ​@@webrevolution. I am making a meme video on America'a gender crisis.
      I got shocked when I saw multiple gender options on Netflix's software Engineer job application lol

    • @Manas-co8wl
      @Manas-co8wl Před 6 měsíci

      Literally same

    • @zabuzagaming5741
      @zabuzagaming5741 Před 6 měsíci

      You are not the only one Same here😂

  • @lucasferrero123
    @lucasferrero123 Před 6 měsíci

    Thanks Kevin, you've explained really well the concepts behind this animation.

  • @royhyde8842
    @royhyde8842 Před 9 měsíci

    As always, thanks for the great content Kevin.

  • @oscarh4066
    @oscarh4066 Před 8 měsíci

    You're the best, Kevin! Thanks for the detailed tutorial.

  • @izyo8146
    @izyo8146 Před 9 měsíci

    Always on point, professional explainations, great takes, great work!

  • @goranspasic4977
    @goranspasic4977 Před měsícem

    Ok, this is the best video so far in this area! Thank you so much!!!

  • @spatialoptic
    @spatialoptic Před 4 měsíci

    As always, THANK YOU Kevin!!!

  • @tomcat1112k
    @tomcat1112k Před 5 měsíci

    thanks for this amazing video Kevin. Loved how thorough the lesson was. I'm gonna customize and implement your technique in my University's final project.

  • @chriscarton4728
    @chriscarton4728 Před 5 měsíci

    Everytime I have a problem I realize you already had the same problem and overcame it. Thank you for lighting the way.

  • @ChecoM83
    @ChecoM83 Před 5 měsíci

    It worked perfectly for me! Awesome tutorial! Thanks a lot.

  • @LarryMarkel
    @LarryMarkel Před 3 měsíci

    You are the goat, great lesson, really informative and upbeat!

  • @plastikbeau3695
    @plastikbeau3695 Před 9 měsíci +4

    The reason you can manipulate properties and attributes of elements created with JS is that a DOM element is just an object in JS, the difference is it does not have a context (like a parent element, etc.) before it's added to a document. Everything else is there as soon as it's created. You can even add event handlers and trigger events on it!

  • @codetheworld6721
    @codetheworld6721 Před 3 měsíci

    Thankyou my CSS master, you are the most helpful guy in youtube.

  • @jupa8712
    @jupa8712 Před 9 měsíci

    Hey man the tutorial was awesome. Thanks for share your knowledge 🎉

  • @ROC4Life96
    @ROC4Life96 Před 4 dny

    Well done, great explanation

  • @MrAbbo11
    @MrAbbo11 Před 2 měsíci

    Thanks so much for this, Kevin!

  • @integrateur
    @integrateur Před 9 měsíci

    I had to built this last week and had a hard time, wished I had found your video before haha Merci Kevin!

  • @anirudhk6109
    @anirudhk6109 Před 9 měsíci

    This is so lovely. it's like magic!!

  • @underroad
    @underroad Před 9 měsíci +27

    @KevinPowell this is great demo! I added this code to pause the animation on hover.
    .scroller[data-animated="true"] .scroller__inner:hover {
    animation-play-state: paused;
    }

    • @Thekidisalright
      @Thekidisalright Před 9 měsíci +1

      This is really wonderful so user don’t have to “chase” the button on screen, especially if the animation is any faster than what Kevin showed in the video.

    • @gbrl8633
      @gbrl8633 Před 4 měsíci +1

      good job!

    • @GuebreAdama
      @GuebreAdama Před měsícem

      Great Job, I tried it and it's working fine.

  • @_duongductrong
    @_duongductrong Před 5 měsíci +1

    Wow, that's so amazing, I think it was so complex, but after I saw your video, understood it so easy (sorry for my English)

  • @dmytro_bhn
    @dmytro_bhn Před 8 měsíci

    Thank you my friend. Very useful and gives the site more interactivity.

  • @HuynhLuong227
    @HuynhLuong227 Před 9 měsíci +1

    wow, amazing effect scroll list item, thanks for sharing

  • @mr.rayparis
    @mr.rayparis Před 5 dny

    okay now working, thankyou kev

  • @ThePetekal13
    @ThePetekal13 Před 9 měsíci +1

    I love your videos so much!

  • @mazboost
    @mazboost Před 7 měsíci

    Thanks mate, well done! I just re-created it in nextJS using your code

  • @ELStalky
    @ELStalky Před 9 měsíci +5

    The object returned from matchMedia has a "change" event, by the way.
    Using that, one can react to changing user (and emulation) settings without reloading the page.

  • @WebDeveloper682
    @WebDeveloper682 Před 9 měsíci

    now i see , you are leveling up your animation skills

  • @sarahtoby473
    @sarahtoby473 Před 9 měsíci

    Thank you! I have looking for this feature 😊

  • @aigeek1991
    @aigeek1991 Před 9 měsíci

    this is pretty much exactly what I needed for a project I'm working on, now to just stop procrastinating and actually get to coding

  • @umidjonzoxidov
    @umidjonzoxidov Před 28 dny

    Thank you Kevin!

  • @bw-dude
    @bw-dude Před 9 měsíci

    Hey Kevin, once again great script, thank you!
    The moment I saw this idea I thought, "why stop with left and right?".
    I just played around with it, basically I duplicated the "scroll" animation, renamed it to "scrollv" and changed translate to translateY
    A CSS query to set the list elements to block when direction is up or down, a little CSS manicure and it works already!
    Currently I still have a small timing problem to fix, but I am so happy about this solution already. You just are the man!

  • @fabioborba2268
    @fabioborba2268 Před 5 měsíci

    You really helped me, thanks a lot

  • @nickbrown6754
    @nickbrown6754 Před 9 měsíci

    I have literally just struggled to build exactly this in a project.
    Now im going to have to go refactor it because your solution is so much cleaner and simple to what I did 😂

  • @mundoextrano8892
    @mundoextrano8892 Před 9 měsíci

    Thank you so much, it´s amazing

  • @yeasinarafat540
    @yeasinarafat540 Před 9 měsíci

    thank you so much for the knowledge

  • @SaadAlShiekhAli-sg4dl
    @SaadAlShiekhAli-sg4dl Před 4 měsíci

    bro you are the king, thankssssssssssss

  • @Labastidaa
    @Labastidaa Před 7 měsíci

    Great tutorial Kevin, I followed this to create a React component and tailwind styles

    • @paulab9310
      @paulab9310 Před 5 měsíci

      Hey @Labastidaa,
      I did the same thing! I am using this ininite scroll in my current React project, I decided to go with a separate CSS file for the component I have the scroller on. My only issue is is that the animation seems to work for me only when I hit save on my .js file. If I refresh the page then it all breaks and it does not look that pretty. Should I be adding some sort of hook for it?
      How did you get that .js file to mont every time you refresh the browser?

  • @isabelphillips451
    @isabelphillips451 Před 2 měsíci

    Mhuaaa 😘😘😘😘😘 ... Heaven-sent implementation

  • @amaizingcode
    @amaizingcode Před 8 měsíci

    Wonderful! Thanks!

  • @ahooton
    @ahooton Před 7 měsíci +1

    Kevin, I've used clamp() for the column-gap value which allows me to have the scroller span any viewport width whilst keeping the column-gap responsive. I then added clamp() - with the halved values - to the calc() function. Works great! I was initially having a nightmare getting this effect to work properly until I came across your tutorial. Your solution using calc() with the translate and gap value to correct the animation glitch is brilliant. Thank you!

    • @TurpoChargedGaming
      @TurpoChargedGaming Před 5 měsíci

      Do you have a codepen with your coded version? Would be great to see how you did that! :)

  • @jackwalsh6487
    @jackwalsh6487 Před 9 měsíci

    Thanks for this tutorial Kevin! Now I have to go and change three logo scrollers on my current project because they all use duplicated content as a solution. It should help page load speed too.

  • @mohammedminoddinsharker8460
    @mohammedminoddinsharker8460 Před 9 měsíci

    Hei Kevin, You are not only boss of CSS but also boss of JS. Best wishes.

  • @VidarrKerr
    @VidarrKerr Před 9 měsíci +1

    I am an architect, but I love CSS too. Your Videos are Awesome! Thank You!

  • @ridewithme9422
    @ridewithme9422 Před 5 měsíci

    Just amazing, jussssttttt Amazing. As a beginner who want to start in industry , I hope I get a senior like you. Respect 🚀🚀

  • @John-King87
    @John-King87 Před 9 měsíci

    Another masterpiece ❤❤

  • @MM-um1sq
    @MM-um1sq Před 4 měsíci

    awesome kevin, good job 👏
    I'm currently working on a svelte project and need this option the the website i did it. with typescript , svelte , tailwind, skeleton + css.
    i really enjoyed! ❤

  • @ousssika5359
    @ousssika5359 Před měsícem

    thanks man , thanks mush love

  • @CirTap
    @CirTap Před 9 měsíci

    you might also add the standardised `dir` attribute for RTL/LTR content flow to keep the internal order of things and the right to left animation. You then use that attribute for your CSS selector.

  • @sai_charan
    @sai_charan Před 9 měsíci

    Thanks Kevin!

  • @mateusmattossabarreto2852
    @mateusmattossabarreto2852 Před 5 měsíci

    I have been trying to do something like this for about a week now. Tried to use a queue for duplicating the items, tried all kinds of weird animations and nothing worked, you really saved me

  • @gbrl8633
    @gbrl8633 Před 4 měsíci

    an incredible class

  • @hassaneoutouaya
    @hassaneoutouaya Před 9 měsíci

    Thank you so much!

  • @cspjdbh
    @cspjdbh Před 9 měsíci

    Perfect video!

  • @soype
    @soype Před 9 měsíci

    I hate scrolling sliders because whenever I have to create a new one I forget what I did before. Adding this to my playlist!

  • @harryprowess9871
    @harryprowess9871 Před 8 měsíci

    Respect man 🙌

  • @gr81matt
    @gr81matt Před 9 měsíci

    This one was very cool.

  • @crstnio
    @crstnio Před 9 měsíci

    Hey, I learned something today. 👍

  • @hameeeed5992
    @hameeeed5992 Před 2 měsíci

    rather than adding the list individually within ul , u can create a variable with the list items and a function that concatenates a list with itself. Now within the ul tag, u can map through the concatenated list items (using the function so it doubles), and create a list tag for each.

  • @user-jz4iz2qh9u
    @user-jz4iz2qh9u Před 9 měsíci

    Awesome video! Could be nice making that as a webcomponent.

  • @user-ij9dy7vp9y
    @user-ij9dy7vp9y Před 9 měsíci

    beautiful thing godfather, thanks thanks 👍

  • @rain-2263
    @rain-2263 Před 9 měsíci

    That's what I about to ask for ❤

  • @nomad100hd
    @nomad100hd Před 9 měsíci +3

    If you track the parent's width and the width of the children and put the `forEach` that adds items into a `while` loop, you can continue adding them until there are enough items to eliminate any gaps, regardless of the size and number of child elements.

    • @roy.mancini
      @roy.mancini Před 3 měsíci

      can you share the code you mean? I have a problem when the items are not enough to fill the container. I want to duplicate the items before finish the first cicle.

  • @khanhduy3364
    @khanhduy3364 Před 6 měsíci

    amazing video

  • @normanejm
    @normanejm Před 9 měsíci

    Thank you!!!

  • @beinyourguard
    @beinyourguard Před 7 měsíci

    pretty neat!

  • @Qbikowski
    @Qbikowski Před 2 měsíci

    hey, it works great, is there any way to add option that we can scroll also scroll manually with mouse/touch?

  • @skillzorskillsson8228
    @skillzorskillsson8228 Před 9 měsíci +15

    you probably already know this, but you can shorten the gradient in the mask by using -webkit-mask: linear-gradient(90deg, transparent, white 20% 80%, transparent); so you don't need to write "white" twice

    • @KevinPowell
      @KevinPowell  Před 9 měsíci +15

      One of those things I know when I see it, but never remember that we can do when I need to do it myself 😅

    • @skillzorskillsson8228
      @skillzorskillsson8228 Před 9 měsíci

      @@KevinPowell 😂😅

  • @dadoual2956
    @dadoual2956 Před měsícem

    How can i adjust that to us it in a vertical way ? thanks so much for ur works!

  • @pmakosyo
    @pmakosyo Před 9 měsíci

    man, you save me. Every time i was creating a marquee i have the issue with the sudden cut of the rotation.

  • @LuBre
    @LuBre Před 9 měsíci +2

    A _responsive_ version with no max-width would be ace!

  • @leehoss
    @leehoss Před 9 měsíci

    Nice video - would be good to show in vertical scrolling as well - I assume it would work the same way. Additionally be good if the scroll speed could work of the inner scroll width so you could get consistent speed regardless of content size :)

  • @cwilcox808
    @cwilcox808 Před 9 měsíci +2

    So good, seeing the animation depend on "Reduce motion" not being enabled. And good to see `aria-hidden="true" `being added to the duplicated items, so a screen reader user wouldn't have to navigate through them.
    But what if the images were wrapped in links? The links would still be in the focus order so a keyboard user would still have to navigate through them all. At first I thought the solution would be to use the `inert` attribute instead of `aria-hidden`, making them both hidden from screen readers and non-interactive. However, that would prevent cursor/touch users from clicking on the duplicated links; awkward. The solution is to do what was done before `inert` was supported, add `tabindex="-1"` to the duplicated links.
    As long as we're thinking about keyboard users, how awkward is it to be focusing on links that are animating? That can be addressed by adding a couple of `:focus-within` rules, one to change the `overflow` from `hidden` to `scroll` and another for the `animation` property so it only animates when `:not(:focus-within)`.

    • @KevinPowell
      @KevinPowell  Před 9 měsíci +3

      I don't think I'd ever use something like this for content I expect the user to interact with. Carousels where the user has control are problematic enough, something like this that scrolls by sounds like a nightmare from a UX perspective, even for fully abled users using a mouse.
      That said, I love that you thought about it and came up with some valid solutions to make it work, because you just know a client is going to ask for that 😅

  • @melvinace5
    @melvinace5 Před 9 měsíci

    Awesome!! 🤩🤩🤩. Can you do another version, like with previous and next button? Thanks man!

  • @bikinglikebecker
    @bikinglikebecker Před 9 měsíci

    awesome sauce

  • @ivanvasquez2023
    @ivanvasquez2023 Před 3 měsíci

    esta bueno el contenido, lo he adaptado para Angular y que cubra el 100% del espacio del contenedor, gracias

  • @santoshparker8681
    @santoshparker8681 Před 9 měsíci

    Lovely 😍

  • @prasoon3292
    @prasoon3292 Před 7 měsíci

    It's amazing, is it possible to add and event which speed up the scroll of text when we scroll the page and slowly comeback to normal speed, and the increase in speed is also linear.
    And also change the direction if scrolled up and vice-versa

  • @djelasrca8091
    @djelasrca8091 Před 9 měsíci

    Hi Kevin. Can you, or somebody in the comments, explain how it is possible to change the background of the div gradually based on how much of the section is scrolled? I have 4 DIVS in one section and one sticky div with arrow icon inside it. Now I want to change the background of every div gradually when the arrow points to it. So if the arrow is in the middle of the div the opacity of the background will be 1 and if it is far from the middle the opacity will be lower until it becomes transparent. Is it possible to do this with CSS only? The problem is that i have 4 divs and each of them should change background based on how far the arrow is from the middle of each div.

  • @Karen-fy7mq
    @Karen-fy7mq Před 2 měsíci

    Muchas graciasssss!!!!!!!!!!!!

  • @mafhper
    @mafhper Před 9 měsíci

    About ten years ago, a client asked for a website made in sections that had a side scroll. As much as I tried to convince them otherwise, I had to. It was a cool challenge. I used parallax in some parts. Usability 0, style 10.

  • @growwithdesign
    @growwithdesign Před 5 měsíci

    Much appreciated. Just an idea suggestion - can you create this in React Next JS with Typescript and Tailwind CSS?

  • @gabrielomane-yeboah
    @gabrielomane-yeboah Před 7 měsíci

    The GOD of CSS🚀

  • @jeff-creations
    @jeff-creations Před 8 měsíci +1

    Thanks for the video Kevin. Question: Does Firefox have a Ctrl+Shift+P type option in dev tools? I can't find reduce motion in FF dev console.

    • @jeff-creations
      @jeff-creations Před 8 měsíci

      I got it to work in Chrome like you did though. Chrome is way better for dev tools

  • @reactnative-fc8to
    @reactnative-fc8to Před 9 měsíci

    How to enable drag functionality for an image so that when you press and hold on it and move to the right, the direction changes to the right or reverses.

  • @linusang
    @linusang Před 7 měsíci

    how would you suggest to make it if we want it to be able to drag the scroll?

  • @fiorellafiorito
    @fiorellafiorito Před 9 měsíci +1

    Hello! This is a great video, you explained everything so so well (Like you always do haha)!! I was curious, how can i implement the javacript file if I am using react? Like i know i can have JS files along the JSX files that react uses but how would i call/import the JS file? Would I have to do the classic script tag on the html file that every react web app has?

    • @tomg55555
      @tomg55555 Před 8 měsíci

      i was wondering that too! any solutions yet?

  • @jerondiovis6128
    @jerondiovis6128 Před 8 měsíci +7

    To improve JS part a bit, you could add all duplicate nodes to DOM in one go - by first creating a Fragment, appending nodes to it, and then appending fragment to scrollContent.
    Only one DOM modification instead of many, would save some milliseconds on initialization of this scroller.

    • @TurpoChargedGaming
      @TurpoChargedGaming Před 5 měsíci +1

      Trying to learn more JS. Do you have a codepen or link to an example of this? Would be great to see! :)

  • @luisgamez5554
    @luisgamez5554 Před 3 měsíci

    hi. thanks. I small doubt, how to get this working with full width instead of 600px?

  • @user-iv8ec8ti4y
    @user-iv8ec8ti4y Před 7 měsíci

    Hi Kevin, wanted to say thanks - you've been really helping me out as I'm building my own website

  • @matthewliew
    @matthewliew Před 4 měsíci

    How would it work for a vertical slider instead?

  • @davidkonevky7372
    @davidkonevky7372 Před 5 měsíci +1

    I remember trying to add a marquee like this in one of my first projects and suffering because it didn't line up in different screen sized 😭