We need more such tutorials like these. Handling small projects without use of any library is such a great way to learn.
@kevinariza6034 жыл бұрын
Hello people! Also, you can add another event listener to check if the screen size changes and update the size variable accordingly, so it becomes responsive. This is what I did: I Changed this: const size = carouselImages[0].clientWidth; By this: let size = carouselImages[0].clientWidth; And I added this to the script: window.addEventListener('resize', () => { carouselSlide.style.transition = "none"; size = carouselImages[0].clientWidth; carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; }); Thanks for these tutorials, Ed, you are great!
@ihatejart1234 жыл бұрын
unfortunately doesnt work for me :( Any idea or tips? is there a specific position within the script for the new eventlistener to place it in? help would be much appreciated :)
@kevinariza6034 жыл бұрын
@@ihatejart123 Here is the source code, feel free to explore/fork/download it and use it to your own need: github.com/Kevwas/image-slider/ If you want something a bit more advanced, taste this other image-slider I made with Bootstrap: github.com/Kevwas/image-slider-2/ Here there is another good example: w3schools.com/howto/howto_js_slideshow.asp
@annaylak26183 жыл бұрын
thanks for this! it works on my code. Issue was, when I click next or prev, it doesn't fully show the full picture.
@kevinariza6033 жыл бұрын
@@annaylak2618 Glad it helped you :)
@stormyandink85493 жыл бұрын
thank you so much! You've saved me!
@tinycabincreative5 жыл бұрын
13:43 "Fired" Relatable. Haha Thanks for such a great tutorial this has been a huge help, you're a wicked coder and I would love to see more.
@kazimuntasir3 жыл бұрын
@Santino Hector I have followed all instructions, but my carousel isn't working. Would you please kindly send me your code...so that I can find my error. Thanks
@tonysmarks35785 жыл бұрын
I'm happen to use carousel in my project and I don't want to require bootstrap. So this is a great video for me!!!
@InGreed6665 жыл бұрын
same here but somehow the javascript doesnt seem to work on my page at all.. idk what going on
@hamzadahmani94894 жыл бұрын
@@InGreed666 make sure if you linked the js file well
@mouhamaddiop11444 жыл бұрын
It's always better to do things by yourself, especially if it's for learning purpose. Thank you very much for what you do.
@developedbyed6 жыл бұрын
Thanks for the positive feedback on these tutorials so far. Let me know if you want to see something else!
@Student-fd4go6 жыл бұрын
Works well, unless you use a page that's not full screen or resize the page during use, can you explain how to make it mobile/resize friendly?
@sugandharao42215 жыл бұрын
Can you show how to add radio buttons at the bottom and control navigation of slides with that?
@armanhanda5 жыл бұрын
Hey! Great tutorial man! Any idea how we can use touch gestures like swipe left and swipe right to fire the previous and next events? Also, will this be responsive to viewport size? Thanks 🙏🏼
@ayyubayyyub94155 жыл бұрын
How old are you ed please tell me
@kulumwangu33664 жыл бұрын
Hi Dev I have a query my buttons do not want to work please assist
@eymeen2 жыл бұрын
I was searching in youtube about this, I opened this video and when I see your intro I was like "YEEEEEEEEESSSSS" I missed your tutorials a lot, I'm now a laravel guy...
@Rob-cq1nf2 жыл бұрын
oldie but goldie :) I really enjoy your "older" content. Keep up the good work
@Photo-Ninja Жыл бұрын
For responsiveness don't use the JS solutions posted below, just use this simple css: .carousel-container { width: 60%; margin: auto; overflow: hidden; } .carousel-slide { display: flex; aspect-ratio: 2 / 1; /*
@quangtoanta85773 жыл бұрын
There're many tutorials out there but only you have videos giuding me with your voice and It's really understandable and really useful. Again, thank you alot!
@marcjosephmanarin7786 жыл бұрын
my problem is this Cannot read property 'id' of undefined. at this line if (carouselImages[counter].id === 'lastClone') { please help me
@chrisj.26114 жыл бұрын
Yap, same here.
@chrisj.26114 жыл бұрын
I dont know why but after I used this part (found it way below in the comments) and just renamed the variable names (b/c i gave it different ones) it worked for me: carouselSlide.addEventListener('transitionend', () => { if(carouselImages[counter].id === 'lastClone') { carouselSlide.style.transition = "none"; counter = carouselImages.length - 2; carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; } else if(carouselImages[counter].id === 'firstClone') { carouselSlide.style.transition = "none"; counter = carouselImages.length - counter; carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; } });
@codenamegrant4 жыл бұрын
8:46; I found that making changes to the code and refreshing the page responds with the incorrect clientWidth, and so my slider remains on the lastClone image. I dont know why this happens, but to fix it, I have to use Ctrl+F5 to refresh the page instead of a normal refresh/reload.
@mayankkumar14173 жыл бұрын
It also happening with me , did you solve the problem now?
@mayankkumar14173 жыл бұрын
I think the first carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; is not working everytime.
@dCoder922 жыл бұрын
The noises your mic is doing is real ASMR for me, thanks!
@lefka25233 жыл бұрын
console.log(counter) error does not work. everything is working but the counter does not work. can someone tell me why?
@gejohans3 жыл бұрын
My get often stuck when I open the page but when I refresh, it's ok. What have I done wrong?
@taruntomar79473 жыл бұрын
Thanks for saving my job.I now feel confident.After looking more than 50 videos I finally got what I was looking for..(subscription-Done). Love from India
@eshendetesia37762 жыл бұрын
Ed, you are the best teacher on the internet. The way you explain the things are very easy to understand!
@Richard-wh6wg5 жыл бұрын
I've used the same code as you did, but that didn't work out. So, I have made mine one following the same logic, and it worked out. Thx my man
@andreistar05334 жыл бұрын
can u tell me the code it doesn't work for me either
@jorgeartaza90305 жыл бұрын
the code doesn't work can you help transitionend section doesn't work.
@dewanshpatle36304 жыл бұрын
Same
@dewanshpatle36304 жыл бұрын
If you find the solution do tell me
@tokochagunava54783 жыл бұрын
guys, how to add auto slide on shits in js? for example after 5-10 second's slide automaticly?
@jnnnle5 жыл бұрын
Wonderfully crisp and to the point, thank you for a grwat tutorial. It would be helpful if you linked the source code.
@william.darrigo2 жыл бұрын
thank you! this was the only tutorial I could find that could do a nice smooth carousel. You explained it awesomingly.
@obelisk26764 жыл бұрын
Lovely video, forgot to link the css file and spent 5 minutes reading out each line of code. Keep up the good work!
@AJ-Pixelyze8 ай бұрын
Good tutorial, my question is, why clone when you could have reset how you access to display the element would the "transitionend" event still work? I built a slider but everytime I press on the next or prev to reset the position it automatically slides to that original element and not doing what your slider does.
@EffuseDex6 жыл бұрын
Loved this, super helpful!
@seantownz45192 жыл бұрын
Im confused with the first clone and last clone. I have the transition but but the first image doesnt transition back to the last image. It just keeps going till i run out of images
@udhavkansal33784 жыл бұрын
Hey Ed, I didn't get the counter part. what is counter doing and how you shift the original image in the slider?? plz help me.
@bazlajter15254 жыл бұрын
God bless you man! After much torment, I found your video and made an infinite carousel. Thanks a lot!
@kazimuntasir3 жыл бұрын
I have followed all instructions, but my carousel isn't working. Would you please kindly send me your code...so that I can find my error. Thanks
@gmanpublications5 жыл бұрын
Hi, I am following along with the video and I noticed a couple of things. First is that there is more than one image instead of only showing one at a time. The second is when I ran the following code... carouselSlide.addEventListener('transitionend', () =>{ console.log('Fired'); }); No fired doesn't show up when I click next.
@MuhammadShahbaz-fg4jh4 жыл бұрын
For one image at a time, check your css, in parent container, use overflow:hidden
@Jehovah774 жыл бұрын
i had this problem my problem was in this line carouselSlide.style.transition = "transform 0.4s ease-in-out" 0.4s was 0.4 so fired didn't work.
@andreistar05334 жыл бұрын
I have an error it says Uncaught TypeError: Cannot read property 'clientWidth' of undefined
@garethbaldwin64134 жыл бұрын
same
@davidegg18204 жыл бұрын
same
@Dev-qy7wv4 жыл бұрын
the issue is with browser compatibility. Chrome supports clientWidth very well but firefox has issues with this property. As a quick fix I hard coded the value of size.
@IstvanWeisz_logoby Жыл бұрын
greatest slider video that I see!!!! Thanks Ed!!!!!
@kevinsing89485 жыл бұрын
the code is messed up the moment you add carouselSlide.style.transform= 'translateX(' + (-size*counter)+ 'px)' the following happens : scroll with mouse to zoom in and out and you will see multiple images within the frame(60% width border). images dont fit border, only works with 100% zoom, change the zoom and enjoy your headache.
@tadas47855 жыл бұрын
It happens because size property is set upon page load. It is constant and doesn't change if you zoom or resize window. You can zoom page and then refresh, after that it should work fine. In fact this carousel is responsive, because it is not so common to change window size during use-time. If you want to make it 100% clean, just add an event, which would change 'size' property if page is resized. Like this: window.onresize = () => { size = carouselImages[0].clientWidth; carouselSlide.style.transition = "none"; carouselSlide.style.transform = "translateX(" + -size * counter + "px)"; }; And don't forget to set size as 'let' variable, since you can't change value of constant.
@kevinsing89485 жыл бұрын
@@tadas4785 thanks for the replay, yah i figured that later,
@TheJFMR4 жыл бұрын
hahahaaha enjoy your headache
@gom4stick4 жыл бұрын
Hi Dev, thanks for this amazinz video. im doing my own webpage and I got a problem with the imgs. In your video, the images fill up the container: carrousel-slide. Im trying to do the same, but mines doesnt. when i code display:flex, they go one beside the other, but they dont fill up the container. I gave them the exactly width and height on PS, but the same. is there something you could recomend. please...!!! thanks Cristian
@Tien-Tjie4 жыл бұрын
did you figure it out im having the same problem
@yourpaldrewdle38934 жыл бұрын
set the width and height of the image to the same width and height of the container
@tunaralyarzada2 жыл бұрын
i have also same issue)
@cyntheatimothy58122 жыл бұрын
Try increasing just the height..in my case setting height to 700px fixed the issue
@HotDogRacing2 жыл бұрын
For me @8:51 If I check in the console with console.log(carouselImages[0].clientWidth) it returns the correct width, but if I do console.log(size) it returns 0.
@nielfollero54 жыл бұрын
That transform = translate in js is bothering me. You used + in both previous and next, it should be moving in the same direction whichever button you click but wasn't. I'm mind blown but I'm sure I misunderstood this. Can someone explain?
@IshratJahan-bf6fw3 жыл бұрын
My images are not fitting into that black box behind the images all the images are cut half in other images it is not a full image .. I hope you understood my problem and will able to help me.
@iqronegoro15382 жыл бұрын
this is what i search for a week
@mailomailo4 жыл бұрын
hi, i'm having the problem that the script is not working at all. i tried various options like external file or inline sricpt - that should not be the problem... please help me
@zdarofMERGAITES4 жыл бұрын
Uncaught TypeError: Cannot read property 'clientWidth' of undefined I get this kind of headache, and buttons isnt doing anything...
@matahoneyy4 жыл бұрын
same hereee! help
@tahirahmedt91564 жыл бұрын
@@matahoneyy check if you are using queryselctor or queryselectorall
@rezzailham76824 жыл бұрын
same here,, help please
@mitchellmadden1834 жыл бұрын
same hereee. i even tried setting the size to #lastClone.clientwidth and nothing happens
@SammyLame2 жыл бұрын
I just dont undersrand the syntax behind how we write this transform translate, and the way we use qotation marks and closures. Also cant find any information about it
@MissDeeJoy5 жыл бұрын
Thank you so much for this tutorial ! It helped me a looooot ! Your explainations are very clear considering JS is soooo complicated haha thanks mate !
@kazimuntasir3 жыл бұрын
I have followed all instructions, but my carousel isn't working. Would you please kindly send me your code...so that I can find my error. Thanks
@tiaan_va2 жыл бұрын
@@kazimuntasir maybe learn some more actual JavaScript before you do these tutorials. The point of this is not to copy his code but to see what logic is needed and if you know even basic js you can use this logic to build it without needing to copy code. There is no point to copy code if you don’t know how to debug it.
@kazimuntasir2 жыл бұрын
@Tiaan van Aardt Thanks brother.❤️❤️
@IshratJahan-bf6fw3 жыл бұрын
Can you tell me what was the size of the pictures of yours? Because it is not matching with mine. I have been trying these pictures resolution code for 2 days but I still can't get it right... I hope you can help me ASAP...🙏🙏
@afyaali46184 жыл бұрын
hello ! my prev and next button not working .please why?
@rakeshsoni88583 жыл бұрын
I wrote the same code for 1920x1080 resolution pictures but when I am resizing it the site is not looking much responsive
@geekprobin14564 жыл бұрын
Great Video about image slider! Especially that sliding effect is really awesome.
@alexlowe98634 жыл бұрын
This is one of the best tutorials on this topic. It's short and sweet. Thanks for the great video. It was exactly what I was looking for.
@cosmicbeam75054 жыл бұрын
Nice Video. Why does clientWidth return 0 when I reload the page? Is there a solution ?
@berintandaniel16433 жыл бұрын
the script stops working if u reload from the button but if you ctrl+f5, everything is fine?
@linad20864 жыл бұрын
Hey the Video is great but could you pleease add the bubble Buttons description?
@rhyler7334 жыл бұрын
yes that would be really nice to know :)
@TWspk663 жыл бұрын
Thank you for the tutorial ! I would like to know how to solve the error : it keep saying that : "app.js:11 Uncaught TypeError: Cannot read properties of undefined (reading 'clientWidth')" @@ it makes i press prev or next btn , it doesn't work :(
@hebasalem9495 жыл бұрын
thank you very much .... i need to add a pagination or bullets at the bottom , do you think you could help me in a simple way like that video? thanks ..
@henrycode6792 жыл бұрын
I always love seeing this my friend coding and learn allot from him.. i wish i see him eye to eye someday 💓💓
@mandyjeans2 жыл бұрын
Actually I based my slider on my website off this tutorial but I have a problem with the slider not actually working on my website until the page is refreshed. Help?
@pranaykrmajee14323 жыл бұрын
My arrows are moving along with the images and disappears after one click. Any solution ?
@alanhanley2142 жыл бұрын
Just came across this video, thank you for a fantastic tutorial, it's just what I needed to help finish my uni project
@mosdev16633 жыл бұрын
doesn't Work for me.. Uncaught TypeError: Cannot read property 'id' of undefined / .id === 'firtsClone' and for lastClone.. Can you explane me please ? Thank you..
@0bbie6105 жыл бұрын
Oof how would you make this mobile responsive. It sizes down my images when i size my window down
@anaisrevellat56925 жыл бұрын
Try to do this like me: you add max-width: xxx px and min-width: xxx px on your .carousel-container, you can test it using Firefox Developer Tool for instance
@freddy73044 жыл бұрын
just declare the elements as a flex box
@arindam12494 жыл бұрын
media query
@oliverbosnjak43612 жыл бұрын
My slider didn't work when dimension of my screen in less then 420px(for mobile version) did somebody know why? otherwise it does everything right.
@rakibhasanrahad69944 жыл бұрын
dev ed bro u are a little bit fast! You are awesome no doubt! But it would be helpful if you add more explanations!
@ganesha123100 Жыл бұрын
Excellent video. Many thanks for taking the time to create this awesome tutorial.
@okepaul85094 жыл бұрын
Great tutorial, I want to know if the JavaScript would work for multiple sliders on a page or I'd have have to duplicate the JavaScript for as many sliders as I would have on the page?
@syrgakomuraliev5 жыл бұрын
says that there's no property of .clientWidth
@matanshtepel12305 жыл бұрын
Same!
@Amoniixx5 жыл бұрын
@@matanshtepel1230 script tag has to be put right before the body tag ends, so basically at the bottom of the html code
@robzlegz4 жыл бұрын
Uncaught TypeError: Cannot read property '0' of null at main.js:27 at this line: const size = carouselImages[0].clientWidth;
@mohdsahil226 Жыл бұрын
Really Thank you so much for this wonder full trick. Please add more components like this! I would like to buy a course if you have one
@edgybedgy4 жыл бұрын
ty for the easy explanation! unfortunately the slider isn't working on firefox, do you have an idea how to fix that?
@avess1005 жыл бұрын
Do you have a github repo link for this?
@mastercoder61974 жыл бұрын
I get error saying cannot read property 'clientWidth' of undefined
@nguyenvinh1853 жыл бұрын
Thank you. Great tutorial. Please tell me which theme you using in visual studio code?
@marcozoni91162 жыл бұрын
Uncaught TypeError: Cannot read properties of undefined (reading 'clientWidth')
@henriquedeveloper81014 жыл бұрын
This man is under the influence of something
@azone16845 жыл бұрын
can i use this method for videos or it works only with images and what about responsiveness? please teach us.
@haykrandeksikik6 жыл бұрын
Sorry i can't understand this part of code ? can you help me a little... how is the first or last picture appearing in left or right when i am sliding ...please help :) if(carouselImages[counter].id==='lastclone'){ carouselSlide.style.transition='none'; counter = carouselImages.length-2; carouselSlide.style.transform = 'translateX('+ (-size *counter)+ 'px)'; }
@mahdiehsani69933 жыл бұрын
So far you are one of my favorite teacher, also you make me laugh during ur explaining 😅
@曰_曰 Жыл бұрын
amazing tutorial!
@kapitankurek4 жыл бұрын
hey I have a problem with the photos being stretched or tightened-up when there is not enough space or too much space. How to fix that?
@pedramkarimi18194 жыл бұрын
object-fit:cover ; write this into your css code.
@pro-truth2 жыл бұрын
Do you have similar for videos? like if you want to replace those images with video clips
@mohammed-i7865 жыл бұрын
Can you tell me how to autoplay this slider?
@juandiegoolivaabarca47115 жыл бұрын
i wanna to know how i can do that?
@sougataghar11795 жыл бұрын
just add setInterval
@diegovillamil79994 жыл бұрын
Thanks man for this great tutorial, thumbs up and I hope to see more
@ryanwong97434 жыл бұрын
hi there! I'm having an issue when i click next button a couple times it automatically returns to the first image
@sir.buttersworth4 жыл бұрын
I can’t see the arrows. When I inspect the page it’s says the arrows are there, but you just can’t see them.
@mantech5602 жыл бұрын
great stuff mahn.. learnt a lot
@adelminwer26754 жыл бұрын
hey dude ,can you help me out i want to make a smaller version of this to put in a page but it doesnt seem to work how can you help me out?'
@ghjafary13045 жыл бұрын
It was fabulous...Thank you for making it.
@lazaros232 жыл бұрын
greate video once again! can u please suggest correct img dimensions for that carousel? or in general good image dimensions?
@bokimitrovicc4 жыл бұрын
Hi there! i see you are using vs code, as well as I do. I have trouble when trying to set grid-template-are, whenever I save it code transform in one line, can you please be kind and help me ?
@RonyPrime2 жыл бұрын
Now i can create a carousel ...... // Thanks A lot brother......
@BJJNathanSK84 жыл бұрын
const carouselSlide = document.querySelector('.carousel-slide'); syntax error at that part :( Someone know why?
@stefanmrvic46523 жыл бұрын
how to make it draggable left and right with hand icon?
@leolowe225 жыл бұрын
transitionend not working in chrome and the code doesnt work in firefox
@jvincent48544 жыл бұрын
Hmmmm I have a bug for some reason, the first and lastclone will appear for a second before flickering to a different image. It seems it doesn't want to stay on the first or last clone. carouselSlide.addEventListener('transitionend', () => { if (carouselImages[counter].id === 'lastClone') { carouselSlide.style.transition = "none"; counter = carouselImages.length - 2; carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; } if (carouselImages[counter].id === 'firstClone') { carouselSlide.style.transition = "none"; counter = carouselImages.length - counter; carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)'; } });
@jvincent48544 жыл бұрын
Nevermind, I understand now. I had to have a closer look at the order of the images and the fact some are duplicated. This is going to be interesting when making them dynamic.
@amirbashir5463 Жыл бұрын
Is it possible for us to get an automatic slideshow with this same technique 🙏
@ghaith990004 жыл бұрын
why when I use fontawesome icons it doesn't work while using buttons it works?
@PaulCresswellcom4 жыл бұрын
Can anyone help me, its driving me mad. I cant get "const width = carouselImages[0].clientWidth;" to return anything but 0.
@andrey77574 жыл бұрын
my problem was that I wrote document.querySelector('img') but instead of this we need to write document.querySelectorAll('img'), maybe it'll help you
@mauricio_vargas4 жыл бұрын
Your script tag needed to be at the end of the html of the not at the top
4 жыл бұрын
everytime I reload the page, only my clone picture appears and I can't move forward. I think that the counter messes up or something like that. Pls help!
4 жыл бұрын
Fixed it! Just needed to change clientwidth to naturalwidth!
@Jazir-Sanchez4 жыл бұрын
@ thanks for the advice i have the same problem.
@Jazir-Sanchez4 жыл бұрын
never mind did't work for me
@gavintai12 жыл бұрын
I like how you explain what is the function of the code and debugging
@sharriceowens9133 жыл бұрын
my images only take up 50% of the container..so 2 pics are seen at once..what i do?
@chengyugong79514 жыл бұрын
Thank you, but how to make the slideshow responsive when you stretch the window? Looks like if I stretch my window bigger or smaller, the image will display inproperly
@tiaan_va2 жыл бұрын
It is responsive. Resize your window and refresh the page. No normal person will manually resize a window while they are already busy scrolling. The js uses the client width of the element as it is after the page is loaded. It will stay like that until the page is reloaded at a diff size. So if this loads up on a mobile device it will fit to the smaller views. If you want the client width to be responsive then you need to add an event listener to the window size so it updates while the user changes the window size,but this is overkill and will make the page slower for no good reason since 99.999% of people won’t be actively resizing the window after it has been loaded.
@jasongaretthatcher2 жыл бұрын
Great video. Thanks for making it. I occasionally have flickering of the images. Any idea what could be the cause? Is there a solution?
@jasongaretthatcher2 жыл бұрын
I figured it out. Adding -webkit-transform-style: preserve-3d; and -webkit-backface-visibility: hidden; got rid of the flashing.
@cp0bo5932 жыл бұрын
thank you very good explanation learned a lot of mechanics just from this video
@JustinTheVlogger4 жыл бұрын
How can I bring down the photos in the center? because my navigation bar has been covered; also how can I hide the photos when I am going to click the "bars" icon? BTW, I subscribed to your channel last day and I always watch your vids about web dev