Тёмный

JavaScript Interface Challenge: Click and Drag to Scroll -  

Wes Bos
Подписаться 178 тыс.
Просмотров 102 тыс.
50% 1

Today we make a pretty neat click and drag to scroll interface where you will learn a whole lot about JavaScript events!

Наука

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

 

18 окт 2017

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 100   
@neelammishra8135
@neelammishra8135 3 года назад
Thanks so much! I created such a page with touch events, but most of the people visting the page were on desktop, so i needed to add the drag functionality as fast as I could. You saved my life!!!
@radovansurlak7445
@radovansurlak7445 6 лет назад
Thank you so much for these videos and blog posts Wes, I really enjoy them not being so damn nerdy and dry.
@heavydirtysoul1491
@heavydirtysoul1491 4 года назад
when i got to console.log(walk) - i was like 'WOOOOW HOW COOL IS THAT'. it was so rewarding in emotional point. thank you for sharing your knowlege!
@allisontpowell
@allisontpowell 6 лет назад
This is awesome, was looking for this exactly. Thanks
@mrSargi7
@mrSargi7 2 года назад
thank you a lot for this! i've been struggling to implement this on react and your way of explaining really made everything so much easy.
@owltrades
@owltrades 2 года назад
Same
@pablotruffa588
@pablotruffa588 6 месяцев назад
Hi wes, i just landed here and it works like a charm. Im preparing an angular 17 app and i adapted your code. Thanks for the tutorial, i lorn a lot!
@CarloNyte
@CarloNyte 4 месяца назад
Super helpful! thank you for breaking this down the way you did!
@aurelianobuendia24
@aurelianobuendia24 5 лет назад
Great tutorial. I´ve implement this using touch events
@valentino4407
@valentino4407 Год назад
i was struggling to get the math right and this simplyfied my task so much, thank you!!!
@Stefandb
@Stefandb 2 года назад
Awesome tutorial man! wish you also covered the tag part of the cards. Since it kind of breaks it.
@klauskuhlmann5856
@klauskuhlmann5856 Месяц назад
You're great, thanks for this masterpiece
@Dipenparmar12
@Dipenparmar12 Год назад
Amazing tutorial WesBos. Please keep it up.
@wirandhikablogs
@wirandhikablogs 6 лет назад
Hi Wes thank you so much for this awesome screencast. by the way how could i achieve the same resut with my scroll wheel ? i am able to drag to scroll but not able to use my mouse wheel for this horizontal layout items ..
@nnivxix
@nnivxix 5 лет назад
nice, that's really what i want, thank you buddy, keep it up 👍👌
@lijovijayan
@lijovijayan 5 лет назад
you saved my life !
@keyzuniverse
@keyzuniverse 4 года назад
thanks dude i was almost looking for the same tut
@user-df4ps2nx6p
@user-df4ps2nx6p 2 года назад
you make it very simple , thank you
@omkarp9943
@omkarp9943 Год назад
Thank you Mr. Wes Bos!!
@MrGuidogr95
@MrGuidogr95 3 года назад
You're the best man
@YunusParvezKhan
@YunusParvezKhan 4 года назад
Thank You very muchh.. I appreciate your work
@havefun5519
@havefun5519 10 месяцев назад
Cool, BTW, could I use with scroll snap? I tried mouse scroll will be conflict with scroll snap,,,, it won't scroll smooth but jumpy
@sofie3313
@sofie3313 4 года назад
Why does it not work if you have two of these .items sections beloweach other?!??????? I want two scrollable bars on the same page but only the opper one work with the click and drag effect.
@rafaglanc7137
@rafaglanc7137 6 лет назад
how to add touch events to this ?
@weshuiz1325
@weshuiz1325 4 года назад
really helpfull finnaly something good
@hieuminh9402
@hieuminh9402 3 года назад
Thank Bro. I did. Very helpful
@gamegang6112
@gamegang6112 2 года назад
How do you make the scrollbar o when not scrolling?
@vishalj845
@vishalj845 5 лет назад
Thank you.
@papodedevcomjuliancio7599
@papodedevcomjuliancio7599 3 года назад
Thanks bro!
@victordiniz245
@victordiniz245 2 года назад
Thank you so much!!! Just to add, I needed to add a preventDefault to my mousedown event listener too, due to it sometimes not properly seeing the mouseup event otherwise.
@bigk2367
@bigk2367 2 года назад
dude can you please share css of this??
@BaljinderKaur-hd4dj
@BaljinderKaur-hd4dj 2 месяца назад
it really helped me to understand the concept. it works perfectly in desktop view but do not know why it is not working in responsive view.
@isroiljohntolibov6057
@isroiljohntolibov6057 5 лет назад
Thanks for nice video. By the way I found little issue with scrolling. [inside "mousemove" function] after assigning "slider.scrollLeft = slider.scrollLeft - walk" you have to re-assign "startX = e.pageX - slider.offsetLeft" then scrolling works smoothly
@kingwindie
@kingwindie 6 лет назад
what text editor do you use,your workflow is perfect
@Glinkis
@Glinkis 6 лет назад
kingwindie Visual Studio Code. It's free.
@marielatihova2077
@marielatihova2077 2 года назад
Great video! Can we also find the source code in Github or somewhere else?
@ilkayalparslan
@ilkayalparslan 3 года назад
where do you get the css for it ?
@TheMariazapata
@TheMariazapata 4 года назад
Gracias.
@owltrades
@owltrades 2 года назад
Muchas Gracias 👍👍
@alperensozen9525
@alperensozen9525 4 года назад
the job that made you +1 follower in 2020.
@satyampandey2222
@satyampandey2222 10 месяцев назад
Nice vide obrah
@heavydirtysoul1491
@heavydirtysoul1491 4 года назад
it follows a link after its block was dragged. how to prevent that?
@amitmehta28
@amitmehta28 11 месяцев назад
Thankyou so much ❤
@IdanRozin
@IdanRozin 6 лет назад
Can u please share the css?
@fajrinmahyuddin2618
@fajrinmahyuddin2618 3 года назад
why margin on first number item not same with the last item ? the first item more space in its margin than last..
@parasarora5869
@parasarora5869 5 лет назад
sir can you plz tell me why at the end we need to subtract walk from scrollLeft?...I am a bit confused with this. How do you figured out that you have to subtract the walk from scrollLeft?
@robertosalazar7826
@robertosalazar7826 5 лет назад
It doesn't work with IE11
@ericellison2413
@ericellison2413 6 лет назад
wes bos you just saved my ass ......
@snehasamuel7426
@snehasamuel7426 Год назад
i am getting scrollLeft as 0 everytime. Anyidea whyand what i should do?
@meghanarajappa1854
@meghanarajappa1854 4 года назад
can you make this scroll to loop, i mean continuous scroll
@rudrakshjain8492
@rudrakshjain8492 8 месяцев назад
around 8:00, you subtracted the offsetleft value from pageX, can you explain why
@demian5511
@demian5511 3 года назад
Nice. I did the same thing with movementX. It tracks the previous and current x offset and calculates the difference for you. scrollContainer.addEventListener('mousemove', function(e){ if(isDragging){ e.preventDefault(); scrollContainer.scrollLeft -= e.movementX; } }); May be helpful for someone...
@moisescastillo3447
@moisescastillo3447 6 лет назад
share the css please
@a4yster
@a4yster 3 года назад
Bos is Boss. each and every single time.
@jackchilders4858
@jackchilders4858 2 года назад
We can reduce the code by using `slider.scrollLeft += -e.movementX * 3` instead.
@realDominik586
@realDominik586 5 лет назад
Why not just use Mouse​Event​.movementX ?
@SebastianPerezG
@SebastianPerezG 6 лет назад
It will be nice if you can add as a plus an infinite drag.
@meth-method
@meth-method 6 лет назад
Hey Wes! I wanted to share a tip and that is you can do this with only using the `mousemove` event. By checking event.buttons, you can know if the mouse is pressed, that makes mousedown, mouseup and mouseleave obsolete. To calculate how far to move you can store previous event and compare the previous with current events `clientX` property. Then you can get away with only this: ``` let prevEvent; scrollable.addEventListener('mousemove', event => { if (event.buttons === 1) { scrollable.scrollLeft -= event.clientX - prevEvent.clientX; } prevEvent = event; }); ```
@meth-method
@meth-method 6 лет назад
Gotta backpedal here a little. Turns out macOS doesn't have an API for button presses so this doesn't work on Safari, so pretty bad advice from me. Always learning. :)
@alexalannunes
@alexalannunes 4 года назад
font name?
@tacocatgamer
@tacocatgamer 3 года назад
can't get it to work for me :/ not sure if anyone is available to help me out?
@hmmm2686
@hmmm2686 13 дней назад
Why i always got scroll left value 0
@DurBeats
@DurBeats 4 года назад
Hi there, thank you for that great Tutorial! I just wondered how I could do it to always scroll a specific amount on scroll. So exactly one element is in frame. I figured to check wether the scroll was positive or negative, and that works, but how could I animated the new set scrollLeft property?
@Annak942
@Annak942 2 года назад
Disclaimer: this will not actually answer your question but if you need to do it for a project there’s a cool little js library called Swiper that does all that for u and it’s super easy, you can set slidesPerView at breakpoints and cool swipe effects :)
@kingsvilleafricang2823
@kingsvilleafricang2823 6 лет назад
please, can you do one for a vertical div..and also show the css file
@Gutto_o
@Gutto_o 6 лет назад
Check my comment, i have one example at codepen with both scrolls working
@cristighn
@cristighn 5 лет назад
@@Gutto_o Thank you for the codepen!
@yashvarshney4072
@yashvarshney4072 5 лет назад
@@Gutto_o can we do this add the second new class same a function
@syedtaqi732
@syedtaqi732 6 лет назад
i need the coding for this
@xxsaifxx2450
@xxsaifxx2450 4 года назад
can any one explain to me about the srollLeft how could we add a variable to an element and it moves
@uzair004
@uzair004 4 года назад
scrollLeft is property not just variable, it shows how much element is scrolled from left side. maybe variable name should be changed to scrolledPart to avoid confusion.
@user-ct5oo3do7b
@user-ct5oo3do7b 3 года назад
The Element.scrollLeft property gets or sets the number of pixels that an element's content is scrolled from its left edge.
@igoroliveira9146
@igoroliveira9146 4 года назад
Mine does work with the finger on phone or tablet. But it doesn't work when I use my mouse on desktop unless I have the console opened. :/
@uzair004
@uzair004 4 года назад
does it work on touch phone using mousedown, and mousemove ?
@igoroliveira9146
@igoroliveira9146 4 года назад
@@uzair004 It works on my phone if I drag with my finger, but I don't need to do all of this for that. However, the mouse-drag part doesn't work on the computer, I need to use the horizontal scroll bar.
@Dave-rd5bb
@Dave-rd5bb 4 года назад
omg
@Yohoyboy
@Yohoyboy 4 года назад
nice intro
@Yohoyboy
@Yohoyboy 4 года назад
im ontario too
@hasanmithawala1045
@hasanmithawala1045 Год назад
I didn't get it please can anyone help me
@MehmetKeskin-pc6oo
@MehmetKeskin-pc6oo Год назад
Kimi Yrr
@mreddygi
@mreddygi 3 года назад
thanks a lot ,, im using this in vue js,, anyone who wish the same let me know!
@bobsterhubby1
@bobsterhubby1 3 года назад
yes please!
@kishorpustake6682
@kishorpustake6682 Год назад
3:19 js
@dileepnagendra8199
@dileepnagendra8199 Год назад
hey, put the source code please
@ArmandoHinojosaCcamaSARC
@ArmandoHinojosaCcamaSARC 2 года назад
I can't do it in ReactJs xD T.T
@MW3GlitchSA
@MW3GlitchSA 2 года назад
Please post the code mate
@MW3GlitchSA
@MW3GlitchSA 2 года назад
Its like a crime to post a coding tutorial without a link to the full code
@MW3GlitchSA
@MW3GlitchSA 2 года назад
And this thing scrolls wrong way
@bigk2367
@bigk2367 2 года назад
@@MW3GlitchSA I am struggling with css can you share your css?
@MW3GlitchSA
@MW3GlitchSA 2 года назад
@@bigk2367 I use Bootstrap studio to auto generate all css
@TheOlian04
@TheOlian04 6 лет назад
That's one horrible font you got for comments 0_o what's it called?
@shadymohammed3197
@shadymohammed3197 6 лет назад
The theme itself is called Cobalt2
@codingtraps
@codingtraps 10 месяцев назад
neither you showed the css and nor the code, whats the point of making videos like that?
Далее
Vanilla JavaScript: Create A Draggable Slider
17:54
Просмотров 41 тыс.
ЮТУБ БЛОКИРУЮТ?
02:04
Просмотров 418 тыс.
Award Winning Animation With Only 20 Lines Of CSS?
6:59
Drag & Drop With Vanilla JS
19:00
Просмотров 251 тыс.
Drag & Drop with Javascript in 4 minutes
3:58
Просмотров 25 тыс.
Learn JavaScript With This ONE Project!
1:10:26
Просмотров 686 тыс.
HTML Drag and Drop API
29:37
Просмотров 73 тыс.
Master JavaScript Drag and Drop with Chess Example!
28:44
Makefiles: 95% of what you need to know
1:01:53
Просмотров 117 тыс.