Тёмный

Vanilla JavaScript: Create A Draggable Slider 

Conor Bailey
Подписаться 11 тыс.
Просмотров 42 тыс.
50% 1

Hi guys,
In this video we are going to be creating a draggable slider with HTML, CSS and JavaScript.
Thanks for watching and please subscribe.
The font awesome CDN can be found here: cdnjs.com/libr...
Conor

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 81   
@rahee3036
@rahee3036 3 года назад
This tutorial is understandable and absolutely awesome! Thank you very much, sir!
@saifeddine6479
@saifeddine6479 3 года назад
I like the way u explain ... How long have u been coding in javascript ?
@Const-y9q
@Const-y9q 2 года назад
I enjoyed the video. I have a question because of "pointer-event: none" on the wrapper, so I can't click on the boxes even if I attach a click event. How should I solve this part?
@bonfacezane7611
@bonfacezane7611 3 года назад
can you share a pen for this pleaase, can't see where am making mistake
@Technoide1911
@Technoide1911 2 года назад
overflow-x: auto; DOES EVERYTHING FOR YOU! No need to swim in JS for sliders... works on ALL mobile devices...
@oreodevainilla
@oreodevainilla 2 года назад
This is exactly what I was looking for. Thank you so much dude, you saved me :D
@TheFotoGuys
@TheFotoGuys 2 года назад
Thats was exactly what I needed. Amazing tutorial and work! Thank you! :D
@guihgdias
@guihgdias 2 года назад
Thanks for this!! Its possible to animated and smoothing the grabb movement?
@Tony.Nguyen137
@Tony.Nguyen137 3 месяца назад
This is what i was looking for❤thank you
@thanveerahmed1963
@thanveerahmed1963 3 года назад
This is what i have been searching for! Thank you so much
@lullalullafy
@lullalullafy 3 года назад
Excellent! Thank you so much for your time!
@g-kems
@g-kems 2 года назад
Thanks for the tutorial! Can I have the source code so to study it? Because it's a bit annoying to go back and forth.
@rahee3036
@rahee3036 3 года назад
I have a problem when I insert greater than 7 divs in the slider-inner div, it only shows 7 divs/images and doesn't show other images/divs. How to fix this? Thank you.
@Axton_PlayerOne
@Axton_PlayerOne 3 года назад
grid-template-columns: repeat(7, 1fr); bro, first number is solution
@abolfazljamshidi1047
@abolfazljamshidi1047 2 года назад
I have an a tag in each item to transfer to the pages, but because the pointer-events property is equal to none, the link does not work, but when I disable that property, the link works, but it causes problems in the carousel. Where is the problem from?
@kevinhe8188
@kevinhe8188 2 года назад
is it possible to use both horizontal scroll and drag together ? and be infinite too
@expukpuk
@expukpuk 2 года назад
Very nice, simple code and useful ... thanks Mate and God bless.
@Sam-rd5bo
@Sam-rd5bo 3 года назад
How to add touch functionality to it???
@mouadraizada8127
@mouadraizada8127 2 года назад
I have a problem which is when the content of the slider or the slides are links (a tag) when I stop dragging it takes me to the link and I want to stop this. any solution?
@meysamzeynali6968
@meysamzeynali6968 2 года назад
This tutorial is great, thank you for your time.
@dylanjackson3583
@dylanjackson3583 3 года назад
Awesome, thanks Conor, lovely work son
@ChrisErfxo
@ChrisErfxo 3 года назад
Good Tutorial... however i have followed your entire steps.. but the . js file doesn't work.. i don't know anything about ES6 im a beginner..please help to src the ES6 into the html
@codeityt
@codeityt 3 года назад
Can I get the source code of this? Please 🙏
@t.a.n.
@t.a.n. 3 года назад
amazing ! Thank you so much! ...From VietNam
@cemaldenizulucak2994
@cemaldenizulucak2994 2 года назад
Uncaught TypeError: Cannot read properties of null (reading 'offsetLeft'). Help Please
@gerwld
@gerwld 2 года назад
Your selector returns null. It means that your getElementById / querySelector doesn't find the element, probably because you make a typo.
@deepak8586
@deepak8586 2 года назад
If I have more than 10 slider images its not showing up what should I do for that??
@zomalee4512
@zomalee4512 3 года назад
will it work on mobile devices??
@iamflo_m
@iamflo_m 3 года назад
a bit late you may have find the solution already, for me i had to use the touch event for mobile device.
@alexradu1921
@alexradu1921 3 года назад
@@iamflo_m hello, can you provide your source code through a gist or a codepen? Thank you!
@iamflo_m
@iamflo_m 3 года назад
@@alexradu1921 yes sure, the css may be different from the video, but the touch is working. github.com/florentmolle/slider-touch.git
@alexradu1921
@alexradu1921 3 года назад
@@iamflo_m thank you so much
@iamflo_m
@iamflo_m 3 года назад
@@alexradu1921 you're welcome
@iuriraimundo6275
@iuriraimundo6275 3 года назад
I got this to work on mobile with this: slider.addEventListener('touchstart', (e) => { pressed = true; startx = e.targetTouches[0].clientX - innerSlider.offsetLeft; }, {passive: true}); slider.addEventListener('touchmove', (e) => { if(!pressed) return; x = e.targetTouches[0].clientX; innerSlider.style.left = `${x - startx}px`; checkboundary(); }, {passive: true});
@ConorBailey
@ConorBailey 3 года назад
Awesome thanks for sharing!
@deepak8586
@deepak8586 2 года назад
awesome!
@mohammadsadeghi681
@mohammadsadeghi681 2 года назад
yeah, that's it, I found it by very search & practice!! how about you?
@montagetime
@montagetime 2 года назад
Also if you have more than one slides, you can use loops like for, foreach.
@ginoxorion
@ginoxorion 2 года назад
Hero!
@TheMrSammyling
@TheMrSammyling Год назад
For some reason, I can't get the last piece of code with the right boundary to work. Has anyone had this problem before?
@abolfazljamshidi1047
@abolfazljamshidi1047 2 года назад
Nice
@suleymanakilli1713
@suleymanakilli1713 2 года назад
thanks that's really helpful
@НикРелков
@НикРелков 2 года назад
Thank you, good tutorial)))
@alanalenz3969
@alanalenz3969 3 года назад
It didn't work for me. Everything seems ok until 12:13 minutes, after this moment I can´t identify what happened and what changed the result.
@ConorBailey
@ConorBailey 3 года назад
Hi Alana. Do you have your code in code pen? Let me know and I’ll take a look.
@blerdijankoliqi3994
@blerdijankoliqi3994 3 года назад
@@ConorBailey i have the same problem at the same time, can you please help me solve this?
@ConorBailey
@ConorBailey 3 года назад
@@blerdijankoliqi3994 sure mate. Can you post your code on codepen? What errors are you receiving?
@blerdijankoliqi3994
@blerdijankoliqi3994 3 года назад
@@ConorBailey silly me.. the problem was that I wrote another word different from your code.. took me 30min to figure out the problem. Anyway, thank you for your reply!
@ConorBailey
@ConorBailey 3 года назад
@@blerdijankoliqi3994 nice one mate. Glad you got it working 👍
@gefranviana4742
@gefranviana4742 3 года назад
*OBRIGADO, ME AJUDOU BASTANTE*
@prem_nigewan
@prem_nigewan 3 года назад
it is not a mobile responsive..... any suggestions?
@oXuanQuynh-BDCDT
@oXuanQuynh-BDCDT 2 года назад
thank you very much
@giorgishalamberidze8204
@giorgishalamberidze8204 3 года назад
if i have a link tag and then image it down working to go on the link
@iamflo_m
@iamflo_m 3 года назад
thanks for this one
@ConorBailey
@ConorBailey 3 года назад
You're welcome :D
@Spectatour
@Spectatour Год назад
how to make this infinite ?
@vuongqtvn
@vuongqtvn 3 года назад
thanks
@mujganqurbanova674
@mujganqurbanova674 3 года назад
why it doesn't work in responsiveness?
@ConorBailey
@ConorBailey 3 года назад
Hey try this one. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-LPBGK1gqXoU.html Works on all devices.
@mujganqurbanova674
@mujganqurbanova674 3 года назад
@@ConorBailey Thank you!
@iyan2492
@iyan2492 10 месяцев назад
Can i get the sourcode plss
@yourdadsmusic
@yourdadsmusic 3 года назад
When you're pressed down (dragging) and the mouse leaves the browser window, the drag gets cancelled. I think theres a fix for this in jquery but do you know how to do it in vanilla js?
@yourdadsmusic
@yourdadsmusic 3 года назад
ended up fixing this by changing the mousemove listener to the window rather than the slider- window.addEventListener('mousemove', ...
@gamegang6112
@gamegang6112 2 года назад
It's easier with slider.scrollLeft
@gunturajipratama170
@gunturajipratama170 3 года назад
Gg
@tiltify2393
@tiltify2393 2 года назад
lol now Js is hitting me like a truck 😭
@ConorBailey
@ConorBailey 2 года назад
Hi Tiltify. To be honest this video may overcomplicate things. Try this video. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-LPBGK1gqXoU.html It creates the same slider with less code and is also more device friendly.
@tiltify2393
@tiltify2393 2 года назад
@@ConorBailey wow thanks for replying, my code works, but there's just one tiny weeny bit problem When I drag the slider for the first time, it drags just fine. But when I drag it the second time, or more times it drags from the original position. Meaning when I drag it for the second time, It drags again from the middle of the inner div also I checked out the other video( just what I need) , thanks for the link ;)
@tiltify2393
@tiltify2393 2 года назад
@@ConorBailey subscribed :)
@tiltify2393
@tiltify2393 2 года назад
@@ConorBailey nevermind problem has been solved with this code slider.addEventListener('mousemove', (e) => { if(!pressed) return; e.preventDefault(); dragPosition = e.offsetX; let currentLeft = parseInt(window.getComputedStyle(slider).getPropertyValue('--lalala')); slider.style.setProperty('--lalala', currentLeft + (dragPosition - startPosition)) // this part being the one I changed, I wonder why the other one wasn't working
@MatheusLopes-wr5md
@MatheusLopes-wr5md 10 месяцев назад
ja vi melhores
@peoplearecool8766
@peoplearecool8766 3 года назад
Did you copy paste wes bos ? :D lol
@ConorBailey
@ConorBailey 3 года назад
hey thanks for watching. No i didn't.
@peoplearecool8766
@peoplearecool8766 3 года назад
@@ConorBailey hey, thank you for answer, it looked almost like wesbos code, he had same kind of project in his 30 days 30 projects series, that's way I asked, but now I checked it closely and your code is different and looks original, sorry about my unthought comment ...
@peoplearecool8766
@peoplearecool8766 3 года назад
BWT when you are calculating startX by substracting innerSlider.offsetLeft to e.offsetX , instead you can just write startX = e.clientX and then in mousemove function x = e.clientX also, and substracting those two gives length in pixels in which mouse traveled from mouse down to mouse move. OR second version is that you also can use offsetX instead of clientX : startX = offsetX -> x = offsetX and innerSlider.style.left = (x - startX) . So basically innerSlider.offsetLeft is not needed here, but in this case it is always equals to 0 anyways and it doesn't make any noticeable difference. But in the case where inerSlider is positiond inside the slider such that left position is grater then 0 than it will give you slight error in calculation.
@ellsonmendesYT
@ellsonmendesYT 2 года назад
this is not the way to thank him (...)
@NganNguyen-ww1ez
@NganNguyen-ww1ez 2 года назад
thank you a lot
Далее
Vanilla JavaScript: Infinite Scrolling Image Slider
28:02
다리찢기 고인물⁉️😱 Leg Splits Challenge
00:37
Please stop using px for font-size.
15:18
Просмотров 192 тыс.
HTML and CSS Project Tutorial: Pure CSS Image Slider
7:41
Subtle, yet Beautiful Scroll Animations
5:04
Просмотров 1,7 млн
Avoid These 5 Awful CSS Mistakes
20:42
Просмотров 195 тыс.
다리찢기 고인물⁉️😱 Leg Splits Challenge
00:37