How To Create An Animated Image Carousel With CSS/JavaScript

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 232

  • @tharunrajoptimus5229
    @tharunrajoptimus5229 Před 2 lety +54

    You never fail to amaze me. I was watching random stuff and saw this coming. Watched this and I'm sure I won't regret wasting the entire day. Nice video mate.

    • @frp8392
      @frp8392 Před 10 měsíci +2

      npc comment

  • @Free_Bird78
    @Free_Bird78 Před 2 lety +8

    the fact that you literally don't stop to explain for a bit amaze me. how can you keep explaining without hesitating

  • @tumbler9428
    @tumbler9428 Před 2 lety +11

    Wow... the javascript part would have taken me HOURS. So elegant.

  • @korokiri8575
    @korokiri8575 Před 2 lety +12

    hi just found your channel, and just wanted to put it here
    i've been a front end engineer for the past 2-3 years and i found many little things that i newly learn from the way you write the animation Its amazing ! keep it up

  • @chinmayghule8272
    @chinmayghule8272 Před rokem +2

    I spent the whole evening creating a carousel that isn't even accessible, but he did it so easily. The part I particularly found difficult was to keep the carousel responsive and make sure it looks good on all sizes.

  • @bobdinitto
    @bobdinitto Před 2 lety +5

    I enjoyed this and learned a lot but I'll have to watch at least seven more times to absorb it all. CSS selectors are my weak point so I'm always interested in learning new selector tricks.

  • @kakakakaka7955
    @kakakakaka7955 Před rokem +2

    funny how you've mentioned that the CSS might have been difficult here, yet the only part that I struggled to fully understand was the JS script :D Thanks, very informative video!

  • @flyinoctopus
    @flyinoctopus Před 2 lety +17

    Another brilliant tutorial, Kyle. I really appreciate you!
    With your help, I feel like I can truly become a web developer :)

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

    Hi, just found your video here (never seen any of your videos before). 1:18 into the view, paused, subscribed. I can see this is going to be useful...

  • @robertobellotti5941
    @robertobellotti5941 Před 2 lety +18

    Something that confused me for a moment was how in the html we are adding attributes such as "data-active" or "data-carousel-button", yet in the javascript we are referencing those attributes with the syntax "element.dataset.active" or "element.dataset.carouselButton". I was trying to figure out where the camelCased version of carouselButton came from, but it simply gets translated that way anytime you use "data-something" in the html tag, it will be referenced as element.dataset.something. And apparently if you used multiple dashed words like "data-some-thing-else" then it can be referenced as "element.dataset.someThingElse". Ok sure, though I'd recommend using camelCase in your html tags instead for better clarity. For example and will both be referenced as "element.dataset.someThingElse" in the javascript, so might as well use the camelCase in the html too

    • @adaravaks
      @adaravaks Před rokem +3

      Thank you very much, I was questioning the same thing

    • @TLPLounge
      @TLPLounge Před rokem +2

      its in the html documentation that element.dataset-any-thing converts to anyThing if youre gonna reference it in JS

  • @mykalimba
    @mykalimba Před 2 lety +27

    8:20 I'd be interested in seeing a video/article that elaborates on this. I don't see how working with attributes instead of classes makes working with JavaScript any easier. If anything, it seems like it'd take more effort to do the same thing when using data attributes (e.g. typing attribute "data-blerg" vs. class name "blerg", querySelectorAll('[data-blerg]') vs. querySelectorAll('.blerg'), etc.). Any class name collisions (I think that's what you mean by the term "overlap"?) are avoided by having a good HTML/CSS design ahead of time.

    • @ShawnRitch
      @ShawnRitch Před 2 lety +6

      Now that is funny... I was thinking exactly the same thing - except, I prefer using IDs as they differentiate the use of JS from CSS being used. However, this was still a great video to watch. Kyle does a wonderful job making these for us. :D

    • @lovefashro
      @lovefashro Před 2 lety +2

      @@ShawnRitch Classes are better as you might have multiple carrousels on the page

    • @justindion4394
      @justindion4394 Před 2 lety

      @@lovefashro I think you could run into the same problem and you end up with data-carousel-button-2 and on

    • @lovefashro
      @lovefashro Před 2 lety

      @@justindion4394 i was refering to using classes over ids

    • @robwatson826
      @robwatson826 Před 2 lety +1

      One good reason is future maintainability - if you come back to this code in the future and see loads of class names, you could easily be fooled into thinking you have CSS rules to go along with it. Also, a class like “active” is fairly common and could easily overlap with other display styles you have created which could cause odd rendering issues

  • @osamapervezriar387
    @osamapervezriar387 Před rokem

    I give Kyle's videos a thumbs up right after the window opens, and then i watch the video after. quality work bro. Thanks

  • @thomasulatowski3012
    @thomasulatowski3012 Před 2 lety +6

    So concise. A really great example. I learned a lot. Thanks Web Dev SIMPLIFIED!

  • @cocoyana
    @cocoyana Před 2 lety

    这老哥写得可以,最近在准备亚麻前端的面试,image carousel是常考mini app。如果你也再找类似的solution的话,这个老哥推荐,不要找2021年以前的video了,并不是说BEM写法不好,太繁琐了,这个老哥的coding style很棒,逻辑也很清楚,说得也通俗简单,我没开字幕都全部跟下来了。 This bro did a pretty fantastic job! I have been preparing for the amazon FTE interview recently, and the image carousel is a frequently asked question. If you are also looking for a solution to prepare the interview, don't look up the video earlier than 2021, I mean I watched a couple of videos using the BEM method to name the class, that's a good and popular method developer used before whatever in USA or China, but I think it's too redundant. This bro's coding style is pretty good and his logic is great and explains everything in a concise way. I didn't turn on the English subtitle and can follow up on every step with him.

  • @dhanlitozi184
    @dhanlitozi184 Před rokem

    you make something that took me a whole day to make and doing it while talking. that's awesome.

  • @chiptaylor1124
    @chiptaylor1124 Před 2 lety +6

    I learned a lot from this video Kyle. Thank you for all the excellent content you create.

  • @michaelparkernorton4841
    @michaelparkernorton4841 Před 10 měsíci

    Thanks this is going to help a lot as I work to complete my homework assignment for Web Dev Fundamentals II at BYUI this week!

  • @ban_droid
    @ban_droid Před 2 lety +6

    Please make something like this but with swipe gesture too

    • @frankthedsigner558
      @frankthedsigner558 Před 2 lety

      Second that, a quick swiping tut would be a good follow-up video. Love your content!

  • @pazispeace
    @pazispeace Před rokem

    that code looks fancy!
    you explain so well that it is easy to understand what you are doing!

  • @michelaveline
    @michelaveline Před 2 lety

    In Portuguese I would say... "Tu é o cara!!" Once again and again.... thank you.

  • @miguelgra92
    @miguelgra92 Před 2 lety +1

    This was a huge help, even learned a few new concepts! Thanks Bruv!

  • @matthewharting3390
    @matthewharting3390 Před rokem +1

    Is there a reason why you did not put the carousel buttons below the instead of on top? If they were placed below then there would be no need for z-index which can end up overlapping drop-down menus.
    Great video though, I will forever use this carousel. Thank you!

  • @FilledStacks
    @FilledStacks Před rokem

    Great tutorial.
    Great tutorial. Thanks for the clarity in the explanation and adding the additional details that might otherwise go un-noticed.

  • @aleksd286
    @aleksd286 Před 2 lety

    Finally Kyle using proper HTML semantics :D

  • @BBStub3
    @BBStub3 Před 2 lety +1

    Very nice, you make it look so easy.
    If I'll ever make a carousel in 15 min. I'll be awesome,... More awesome then I already am.

  • @rework7562
    @rework7562 Před 11 měsíci

    In this video you use the spread operator on the array (script.js => line 11). I would love to see a more in depth video on this topic because I can't figure out how it actually works in a case like this.

  • @nadavbensimon1267
    @nadavbensimon1267 Před 2 lety

    thanks man i am hoping to be a dev one day.its those types of videos that keep encourge me to cods.keep the good work

  • @aliahmedkhan9690
    @aliahmedkhan9690 Před 2 lety

    this guy has names his channel so honestly.

  • @hjetwd
    @hjetwd Před 2 lety +2

    nice work!
    p.s. replace all :focus to :focus-visible

    • @hjetwd
      @hjetwd Před 2 lety +2

      ​@@Steel0079 :focus adds an outline when you click with the mouse or tap with your finger. Outline is only needed for navigation when pressing the Tab key. To do this, they came up with :focus-visible - the state only when focusing from the keyboard.

  • @koka-on6dt
    @koka-on6dt Před 2 lety

    Your video always useful to me! I just struggled with how to solve the issues of vanilla js and css carousel. Thank you Kyle.

  • @MeezanTheFairBloke
    @MeezanTheFairBloke Před 2 lety

    The way you operated that JS made my head spin :D Great vid though, one of these day I am going to understand exactly what is going on here...

  • @axelpaillaud7542
    @axelpaillaud7542 Před rokem

    It was amazing, and so much simple than some other carousel tutorials, thanks you very much !

  • @aleksandrlavrov9781
    @aleksandrlavrov9781 Před rokem +4

    Thank you for your hardwork. I have always found you lessons usefull. However, the pace in this one is too fast. For beginners it is hard to grasp the idea of the project when you are typing and talking super fast without proper explanation. It is not a speed championship ) be slower please.

  • @Wilespro1
    @Wilespro1 Před rokem

    beautiful way of creating a carousel. Thanks!

  • @prsmahajan
    @prsmahajan Před 2 lety +1

    That ahen moment felt because of Kyle Cook😍👊

  • @mykalimba
    @mykalimba Před 2 lety +11

    11:35 In instances where your offset is always small-ish, these two checks can be replaced with a single calculation:
    newIndex = (newIndex + slides.children.length) % slides.children.length;
    (This assumes there is at least one slide in the carousel.)

  • @akodamathe
    @akodamathe Před rokem

    Clean, easy to understand, that's what I needed. Thanks a lot!

  • @BagelsAfterMidnight
    @BagelsAfterMidnight Před 10 měsíci

    This was a lifesaver. Thank you!

  • @alexisgarai296
    @alexisgarai296 Před 2 lety

    so cool dude, this is exactly the type of learning support I needed - thanks

  • @santoshkadam8431
    @santoshkadam8431 Před rokem

    Honestly overall designing carousel similar to what you did is not big think. Bu t I am simply amazed with the speed.

  • @doomguy2135
    @doomguy2135 Před 2 lety +1

    cant wait to try this with react

  • @nicholaslewis279
    @nicholaslewis279 Před 2 lety

    The JS part was crazy as hell. I was with you until that very moment (probably because that was my very first time typing JS) lmao
    Still managed to do it though with minimal pauses :D

  • @briangrover1625
    @briangrover1625 Před 2 lety +1

    Fantastic tutorial. Thank you!

  • @nikhil6842
    @nikhil6842 Před rokem

    I've seen lots of tutorials but no one came close this.

  • @ajaymishra1511
    @ajaymishra1511 Před 10 měsíci

    Katar patar katar patar and boom 💥
    Image carousel ready

  • @Chuksteve-Live
    @Chuksteve-Live Před rokem

    Thank you very much for this lecture. I have just be able to execute a project with it.

  • @user-vv9qt1ps2v
    @user-vv9qt1ps2v Před rokem

    Man you are my hero.......so smart. I salute you

  • @ajlebeau
    @ajlebeau Před 11 měsíci

    You are undoubtably a rock star! But who is this code "simplified" for exactly? Who is your target audience? I'm a beginner and it's really hard to follow. Regardless, I've learned so much from you. Thank YOU!

  • @carlosz1858
    @carlosz1858 Před 2 lety

    thanks dude, that helped me a lot, greetings from colombia :) have a nice day

  • @bonnes04
    @bonnes04 Před rokem

    you make it look so simple

  • @StaridasGeography
    @StaridasGeography Před 2 lety +1

    Awesome! How about making a part two, where images are loaded from json via the fetch promise? 😉😉

  • @Al-no2fm
    @Al-no2fm Před 2 lety

    Perfect little project for fe devs

  • @Argylleagen
    @Argylleagen Před rokem

    Recently found out your channel and I am mesmerised by your work and skillset. Not to mention, quite jealous! Keep going Kyle, you have yourself a sub

  • @jawndice
    @jawndice Před rokem +1

    You make it look so easy. May I ask how long have you been coding for?

  • @pietrot90
    @pietrot90 Před rokem

    thank you! your tutorials are just amazing!!

  • @_werther
    @_werther Před 2 lety

    Always love your way man, congrats

  • @gustavocastro4697
    @gustavocastro4697 Před rokem

    Helps me a lot, thanks, i appreciate your content a lot!!!

  • @Liquidian
    @Liquidian Před rokem

    Thanks, this was educational and practical.

  • @MusicIsLifeFM
    @MusicIsLifeFM Před 2 lety +2

    Excellent thank you!

  • @andriiauziak1178
    @andriiauziak1178 Před 2 lety

    amazingness in simplicity

  • @amniar8158
    @amniar8158 Před 2 lety

    thanks man never give up

  • @vendettamalize7209
    @vendettamalize7209 Před 2 lety

    nvermind i kept clicking left anyways it worked
    thanks ILOVEU

  • @keinan7667
    @keinan7667 Před rokem +2

    How might you make this slider automatically activate every a few seconds, in addition to using these buttons? - Thanks for the videos!

  • @ademineshat
    @ademineshat Před 2 lety +3

    Nice video. Just for me Personally the way you write JavaScript it's a bit hard to read ✌️

  • @guyfawkes6930
    @guyfawkes6930 Před 2 lety +1

    That's exactly what i need man ❤️❤️❤️

  • @yyk9881
    @yyk9881 Před 2 lety

    This man is the Best! I think Kyle is a genius. 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍

  • @promohican8222
    @promohican8222 Před 2 lety

    You're working so fast damn

  • @PiccolosDaughter
    @PiccolosDaughter Před 2 lety

    "position this ab-so-lutely" *giggles to self*

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

    Great tutorial.

  • @maheshsangam6212
    @maheshsangam6212 Před rokem +1

    this carousel changing image once you click on arrow but is it possible to change it automatically and also work with arrow buttons... i mean slider will move images automatically :)

  • @brendariley2431
    @brendariley2431 Před 11 měsíci

    This is AMAZING!! You are always the best in your tutorials - thank you so much! Just a quick question, but how could you add soe text on top of the images, each slide has something different on it. I tried to embed it within the div's and img src's, but failed... Any kind of advice would be greatly appreciated!

  • @chapidi99
    @chapidi99 Před rokem +1

    I followed your video and developed code, I don't understand why I am not able to slide the photos. I can only see the first image. SOmething wrong with the Js

  • @irfansaputra5744
    @irfansaputra5744 Před 2 lety +1

    How do you make this slides automatically every a few seconds?

  • @Aalok464
    @Aalok464 Před 2 lety

    I was just going to see some new videos of you and you uploaded one video

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

    Thank You Sir!

  • @noxagen
    @noxagen Před 2 lety

    thanks for another lesson bro

  • @mrmrsnobody7662
    @mrmrsnobody7662 Před rokem

    Thanks for this video

  • @TheMetalMag
    @TheMetalMag Před 2 lety

    Wow u kicked my ass, so much knowledge. Thank you!

  • @Mrabdulazizbidani07
    @Mrabdulazizbidani07 Před 2 lety

    Perfect this what I was looking for🥰👍🏼

  • @realestatehomerunspodcast6047

    Great video! I love the video features. Which video editor do you use?

  • @JasonKuffler
    @JasonKuffler Před rokem

    Awesome sauce! Thanks :D

  • @kadirgurcan2847
    @kadirgurcan2847 Před 2 lety +1

    I'm getting this error: "script.js:3 Uncaught TypeError: Cannot read properties of null (reading 'forEach')
    at script.js:3:8", how to fix that?
    It's in this part:
    button.forEach(button => {
    button.addEventListener("click", () => {
    const offset = button.dataset.carouselButton === "next" ? 1 : -1
    const slides = button
    .closest("[data-carousel]")
    .querySelector("[data-slides]")

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

    When doing a querySelector for an element you want to interact with or that might have an event listener, is it common practice to use an attribute to select it instead of a class or ID?

  • @giovannimichel5506
    @giovannimichel5506 Před 2 lety

    Thank you for the intel

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

    شكرا Thanks it was helpful

  • @paleolithix7324
    @paleolithix7324 Před 2 lety +1

    Hello! I really enjoyed this tutorial but even if I copy your exact codes, my Javascript file isn't linking with my HTML file. Im currently using VSC, could you please help me?

  • @Amanpreetkaur16
    @Amanpreetkaur16 Před 2 lety +1

    Thanks ❤️❤️

  • @yunalee6221
    @yunalee6221 Před 2 lety

    You're the best!!!Thank you :)

  • @rameenana
    @rameenana Před rokem

    Thanks man. Very useful video.
    How can we add auto slide to this?

  • @Satishkumar-rx7oy
    @Satishkumar-rx7oy Před 2 lety

    very helpful tutorial

  • @burgasdragonheirsilentgods

    Great stuff man !

  • @JosephM1M5A4
    @JosephM1M5A4 Před 2 lety

    Thank you

  • @brendensong8000
    @brendensong8000 Před rokem

    So simple, but very effective!!! love your videos!

  • @jorgemeza4364
    @jorgemeza4364 Před 2 lety

    You rock man

  • @goldmikanik8274
    @goldmikanik8274 Před 2 lety +4

    Not simplified anymore.
    I know you are trying to keep the video short, but this is too fast for me.
    I would prefer watching one hour instead of pausing and playing back.
    Still amazing channel 👍

  • @justindion4394
    @justindion4394 Před 2 lety +2

    This video is great! I tried to replace the arrows with ‹ and › because I think they are nicer but they do not center properly. Does anyone else have this issue?

    • @chiptaylor1124
      @chiptaylor1124 Před 2 lety +3

      Yes, but only in Firefox. It looks fine in Chrome. I have spent quite a lot of time trying to find a solution. I have tried using -ms-transform: translateY(-50%). I have also tried putting the arrows in a span and using flexbox to center vertically, but the span just takes up the entire height so that didn't work. Still stumped, does anyone else have ideas?

  • @sashanilssen
    @sashanilssen Před rokem

    This tutorial was great, I had some issues but I solved them eventually. My only gripe is that the arrows seem arbitrary, as clicking either of them has the same effect and scroll in the same direction. I'm new to JavaScript so I don't know how to fix this myself, where would you recommend I start with that?

  • @pradnyeshmali4207
    @pradnyeshmali4207 Před rokem

    Actually doing position absolute on .slide class bring all bottom elements on top of the carousel how to avoid this?

  • @mohdgulzar5178
    @mohdgulzar5178 Před rokem +1

    How can i make images automatic change

  • @sivaprakash_prabakaran

    how to make the images slides automatically after certain seconds, instead of using buttons?