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
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?
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.
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?
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?
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
@@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!
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?
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.
@@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 ;)
@@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
@@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 ...
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.