How To Create An Image Slider In HTML, CSS & Javascript
Video Statistics and Information
Channel: Dev Ed
Views: 354,234
Rating: undefined out of 5
Keywords: image carousel javascript, how to create an image carousel, html, css, javascript, how to web development, bootstrap alternative, vanilla javascript, How To Create An Image Carousel In HTML, CSS & Javascript, dev ed, image slider tutorial, javascript image slider, jquery image slider
Id: KcdBOoK3Pfw
Channel Id: undefined
Length: 24min 42sec (1482 seconds)
Published: Sat Jun 30 2018
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
Some notes:
All this code is in the global namespace, might want to wrap this all into a function/class so there aren't conflicts.
I'd probably put the transition into CSS, and disable it by adding a class. Separation of concerns and all that. E.g.
carouselSlide.style.transform = 'translateX(' + (-size * counter) + 'px)';
gets repeated a lot, could probably be abstracted. E.g.Since you're using
querySelector()
for thecarouselSlide
and button variables, a user wouldn't be able to have multiple instances of carousels in the page. Swapping those and then wrapping the code in a foreach would be pretty sweet.If a carousel isn't present on the page, you'll get an error
Cannot read property 'clientWidth' of undefined
. Should probably return early ifcarouselSlide
doesn't exist.Someone requested a responsive navbar, feel free to request other tutorials aswell. Support should be good on this, all the way down to IE 10.
Nice job. Thanks for making this.
To those of you wondering, you can download the vanilla js framework here. Its actually surprisingly lightweight.
Would be great if you threw the finished product up on a JSFiddle!
Nice tutorial! You should do an extension on this, creating the alternative infinite carousel.
E.g. Navigate right === take first item in array and throw it to the back of the array, navigate left take last item and insert in beginning of the array.
Third installment could touch on FLIP (first, last, invert, play () => { https://css-tricks.com/animating-layouts-with-the-flip-technique/ } );