Learn JavaScript Touch Events In 17 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ค. 2024
  • Mobile responsive design is something everyone focuses on with CSS, but touch events are something almost no one takes the time to implement. In this video I will show you how to get started with touch events, how to connect your phone to your computer for debugging, and overall how to make working with touch events easy.
    📚 Materials/References:
    Chrome Devices URL: chrome://inspect/#devices
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:55 - Touch event basics
    03:54 - How to debug your phone from your computer
    07:40 - Advanced touch event features
    #TouchEvents #WDS #JavaScript

ความคิดเห็น • 154

  • @diegolopez9851
    @diegolopez9851 2 ปีที่แล้ว +15

    You are uploading all the videos I'm needing this week 🤯🤯

  • @tuhinkarmakar3882
    @tuhinkarmakar3882 2 ปีที่แล้ว +24

    This literally answered a ton of doubt that I usually had while building some touch based stuffs. Thanks a ton @Kyle :)

  • @SamFishback
    @SamFishback ปีที่แล้ว +14

    Thank god for you. A clear, concise crash course on touch events. I have been scouring the internet only to find documentations and outdated stackoverflows. This was exactly what I needed.

    • @scienceblossom6197
      @scienceblossom6197 ปีที่แล้ว +1

      I agree, thanks God he's such an amazing teacher! 👌👌👌

  • @ronny332
    @ronny332 2 ปีที่แล้ว +1

    Nice introduction to topic, I never came across until now. Thank you 🙂!

  • @matteoporrani4271
    @matteoporrani4271 2 ปีที่แล้ว +1

    Great video, simple and clear, thanks a lot!

  • @emyralunthomas
    @emyralunthomas 2 หลายเดือนก่อน

    Really clear and to the point explanation - great work

  • @politubeyou
    @politubeyou ปีที่แล้ว

    Great explaination in such a short time. Thank you!

  • @smoothbeak
    @smoothbeak 2 ปีที่แล้ว +1

    Wow, touch events are quite interesting, and fairly simple to work with really :) Great video

  • @felipefregginrules
    @felipefregginrules 8 หลายเดือนก่อน

    This is super! Thanks so much Kyle!

  • @StellarWeb008
    @StellarWeb008 2 ปีที่แล้ว +6

    He's the best teacher I have every seen
    And from now on he is my favourite youtuber also

  • @Kawabolole
    @Kawabolole 2 ปีที่แล้ว +2

    awesome and super useful, thanks!

  • @kenkinyua7036
    @kenkinyua7036 2 ปีที่แล้ว

    this is really my favorite channel . Thanks

  • @alessandroformica6824
    @alessandroformica6824 ปีที่แล้ว

    Another cool video from Kyle. Thank you, Mister!

  • @tigersmith12
    @tigersmith12 2 ปีที่แล้ว

    W wat a great guide W you not only gave great real world use case scenarios but you also show a fast and simple way to debug any and all examples. There has been times where I followed a guide and ran into a bug that wasn't explain in the demonstration and couldn't figure out how to properly debug it. Ppl would pay crazy amounts of money to get half of this effort and quality at a college. One more W for good measure. P.S. I don't even web dev but love it when I see a good and clear guide.

  • @user-xb7wq5kp5l
    @user-xb7wq5kp5l 2 ปีที่แล้ว

    Thanks a lot Kyle. extremely useful and interesting topic and video.👍

  • @FxWitch
    @FxWitch 3 หลายเดือนก่อน

    Absolute game changer, this saved me tons of time researching these things as a noobie

  • @davidrobot7818
    @davidrobot7818 2 ปีที่แล้ว

    Great tutorial. Thanks.

  • @scottlexium
    @scottlexium 2 ปีที่แล้ว

    How I love watching your videos immediately released 😫

  • @mr.jitruxa8103
    @mr.jitruxa8103 9 หลายเดือนก่อน

    thank you for this video, it helped me a lot!

  • @sivakarthikeyan2516
    @sivakarthikeyan2516 ปีที่แล้ว

    Thankyou man, you made me happy. 🙂

  • @AndyRocket1000
    @AndyRocket1000 ปีที่แล้ว

    Great job kyle👏👏👏

  • @saifsaeed1158
    @saifsaeed1158 2 ปีที่แล้ว

    well done my man , thanks alot

  • @shahabdev2520
    @shahabdev2520 ปีที่แล้ว

    super cool man. super cool. gracias

  • @QwDragon
    @QwDragon 2 ปีที่แล้ว

    Very cool! Thanks!

  • @sasi_smr
    @sasi_smr 2 ปีที่แล้ว

    Amazing!! You are awesome!!! ❤️

  • @OscarSerna-
    @OscarSerna- ปีที่แล้ว

    Thanks!

  • @Aalii6
    @Aalii6 2 ปีที่แล้ว

    interesting topic, thank you!

  • @MrSantirangel
    @MrSantirangel 2 ปีที่แล้ว

    Great Video!!

  • @SiddheshNan
    @SiddheshNan 2 ปีที่แล้ว +15

    Hey Kyle great video as always! Btw I noticed one thing that the about Phone menu is actually leaking your phone number & imei at 4:19 Please add some blur or box to hide it. Thanks.

  • @AnkitTiwari-dq7qm
    @AnkitTiwari-dq7qm 2 ปีที่แล้ว

    Awesome Video 🔥

  • @dclxviclan
    @dclxviclan ปีที่แล้ว

    Awesome bro, thanks for that lesson, u help me, this good lesson👍

  • @mrmike81818
    @mrmike81818 2 ปีที่แล้ว

    Thanks for sharing your mad skills... impressive.

  • @JimRooney
    @JimRooney 2 ปีที่แล้ว

    Top shelf 👍🏻

  • @riyaanfarhaan754
    @riyaanfarhaan754 2 ปีที่แล้ว

    Oh, thank you kyle. Just saved me from going on searching about touch events. Once again thank you.

  • @Dipenparmar12
    @Dipenparmar12 ปีที่แล้ว

    Amazing tutorial

  • @robinwatts8374
    @robinwatts8374 2 ปีที่แล้ว

    You're the man

  • @Paninicus
    @Paninicus 2 ปีที่แล้ว +3

    yet another high value video. Thanks Kyle. A similar video about debugging on iOS would be awesome. Because remember, Safari is the new IE...

    • @Weagle1337
      @Weagle1337 2 ปีที่แล้ว

      Just install another browser...

    • @Paninicus
      @Paninicus 2 ปีที่แล้ว

      @@Weagle1337 sure, I'll tell my 12k users

  • @dustinscroggins6256
    @dustinscroggins6256 2 ปีที่แล้ว

    Perfect video bro

  • @atroyo6504
    @atroyo6504 3 หลายเดือนก่อน

    Damn, this is like a bite-sized course. Pretty concise without sacrificing details.

  • @mnnw148
    @mnnw148 ปีที่แล้ว

    great video

  • @gopalloharnew5948
    @gopalloharnew5948 2 ปีที่แล้ว +1

    It's Ammazing !

  • @squarerootof2
    @squarerootof2 2 ปีที่แล้ว +4

    This touches me deeply!!

  • @reyzKhight
    @reyzKhight 2 ปีที่แล้ว +3

    This is what I'm looking for

  • @addictedSK
    @addictedSK 2 ปีที่แล้ว +1

    i was just working on something for mobile browser the other day and I've used on click everywhere! got to learn a lot from this.... can you please do tutorial for holding down plus minus button to gradually speed up number? Thanks

  • @andrillaf
    @andrillaf 2 ปีที่แล้ว

    Ha! You read my mind. I was just struggling with this!

  • @fransjoakimtitulaer2404
    @fransjoakimtitulaer2404 ปีที่แล้ว

    Amazing

  • @reimdl
    @reimdl 2 ปีที่แล้ว

    Super useful

  • @MuhammadAhmedAshraf
    @MuhammadAhmedAshraf 2 ปีที่แล้ว +6

    can you make a video about paper ripple animation when there is not internet youtube have a retry button and when you long press on it the animation goes slow and stays there as long as you click there i am struggling to find this kind of animation that youtube has

  • @amiralishoja
    @amiralishoja 4 หลายเดือนก่อน

    Perfect

  • @mohammadashrafi2033
    @mohammadashrafi2033 ปีที่แล้ว

    Great👍

  • @beinyourguard
    @beinyourguard 2 ปีที่แล้ว

    awesome!

  • @0VexRoblox
    @0VexRoblox 2 ปีที่แล้ว +1

    Very touching

  • @anonlegion9096
    @anonlegion9096 2 ปีที่แล้ว

    6:30 I've been developing for a little over a year now and this just blew my mind

  • @user-hd3pz2ow1b
    @user-hd3pz2ow1b 4 หลายเดือนก่อน

    thanks

  • @tlochsta
    @tlochsta 2 ปีที่แล้ว

    Nice!

  • @CiroPeixoto
    @CiroPeixoto ปีที่แล้ว

    FERA!!! 🦁

  • @ripon59
    @ripon59 2 ปีที่แล้ว

    awesome

  • @amircahyadi9219
    @amircahyadi9219 2 ปีที่แล้ว

    Nice share 👍

  • @ayushtiwari1504
    @ayushtiwari1504 2 ปีที่แล้ว

    The video which I wanted

  • @EvertJunior
    @EvertJunior 2 ปีที่แล้ว

    You're perfect

  • @CirTap
    @CirTap 2 ปีที่แล้ว

    You can also do remote USB debugging in desktop Firefox and connect its DevTool to your Android Firefox instance. Both need to be the same version iirc.
    On desktop goto about:debugging to enable the feature.

  • @broadshare
    @broadshare 2 ปีที่แล้ว

    Hey Kyle, good stuff thanks. When are you playing the guitar 🎸

  • @mohamedyoussef8835
    @mohamedyoussef8835 ปีที่แล้ว

    Awesome video ++++++++++++++++++ 😃

  • @diego_sabbagh
    @diego_sabbagh 2 ปีที่แล้ว

    Thansk for the video. Noob question: what is that semicolon ";" you put in front of the arrys?

  • @sandamandresyrajemisa5767
    @sandamandresyrajemisa5767 2 ปีที่แล้ว

    Nice

  • @devstefancho
    @devstefancho 2 ปีที่แล้ว

    Could you make a video about pinch zoom to magnify images?

  • @martinheywang4962
    @martinheywang4962 2 ปีที่แล้ว

    It works with Firefox as well, and it is a simple as with Chrome. You get even select elements, get flexbox and grid helper (like on desktop), ...

  • @rachidb9624
    @rachidb9624 2 ปีที่แล้ว

    I didn't even know that such Javascript events existed in the first place

  • @user-ye2fw4do4d
    @user-ye2fw4do4d 7 หลายเดือนก่อน

    Hey love your vids, i don't know if you can help me with something, i did catch the vertical movement and i increase and decrese a variable value and i did set each 10 + or - to do anotherVariable++ and anotherVariable-- and run a function func(anotherVariable) my problem is no matter what i try the function its only called 1 time if i console log instead of a function like cons..log(10+) cons..log(10-) it will print as it should but as soon as i change to a real render code it breaks on first call

  • @terencecluttey8302
    @terencecluttey8302 2 ปีที่แล้ว +1

    connecting my phone to the website that is run locally is cool

  • @chrismuller2780
    @chrismuller2780 9 หลายเดือนก่อน

    @14:41, Could you have used stopPropagation() in your event handlers instead of preventDefault() in addEventListener()?

  • @jingsuantan2304
    @jingsuantan2304 2 ปีที่แล้ว

    wanba ask if touch event can set to lock control on resize resolutions of the screen also? 🔒

  • @repenning1
    @repenning1 2 ปีที่แล้ว +5

    Kyle, have you considered pointer events? Would be simple to change your code to make pointer events work, but they would have the advantage of working for touch and mouse at the same time. There is no touch array with pointer event but you don't need that. As you could see the simultaneous touch is nearly impossible anyway. Pointer events are, I think, simpler to implement.

    • @4541047
      @4541047 2 ปีที่แล้ว +1

      Indeed, this is the right and correct comment for this video...

    • @ellieyen3359
      @ellieyen3359 2 ปีที่แล้ว +4

      According to MDN, the pointer event seems to have better browser compatibility (for non experimental properties). Also, the pointer event has more capability to handle things such as pressure and tiltX for pen devices.

    • @anonlegion9096
      @anonlegion9096 2 ปีที่แล้ว

      interesting.... gonna read more into this

    • @alwaysasq7797
      @alwaysasq7797 2 ปีที่แล้ว

      I was considering just click for my (soon to be available) explainer video on programming drag and drop. Then I considered adding touch based on this great video by Kyle - just been testing using pointer events - both in one event! Tested in mobile chrome and edge.

    • @indoom
      @indoom 2 ปีที่แล้ว

      and pointer event has setPointerCapture/releasePointerCapture. Really helpful when dragging stuff around

  • @sohastar1985
    @sohastar1985 2 ปีที่แล้ว +15

    Perfect this time more clear 👍 i like kyle videos cause its clear without extra information . But some times he is too fast on talking like eminem😂 . ✌️Thak you for share your information kyle🤗

    • @nathanyang3288
      @nathanyang3288 2 ปีที่แล้ว +3

      Keminem😂

    • @phil2of3
      @phil2of3 2 ปีที่แล้ว +1

      One could say it's... simplified.

  • @CirTap
    @CirTap 2 ปีที่แล้ว +1

    What about Laptops and Pen / Graphics Tablets? and how do *PointerEvents* fit into the picture?
    Tablets are connected to PC-ish devices (Laptops) and many come with support for pinch and zoom => multi touch points.
    Aren't PointerEvents supposed to be the clicky-touchy "meta" event that cover both touch and click?
    As a (Wacom) pen tablet user that also uses the pen/stylus as a mouse replacement, I always run into issues on web pages that use *drag* events like maps (Google, Apple).
    Several panels in Firefox DevTools also do not respond properly when I try to resize them using the pen.
    It's only web stuff that has this issue. Desktop apps respond perfectly fine to the pen-as-mouse use case.

  • @karshten9218
    @karshten9218 ปีที่แล้ว

    Hi! How make drag and drop on mobile diveces, I've done ordinary dnd on desktop, but on mobile devices it wasnt working

  • @kabkee
    @kabkee 2 ปีที่แล้ว

    Hi Kyle, I've found that a semicolon had been automatically added on the first place of a line. It seems like an auto formatting was working.
    I googled up for the reason for using a starting semicolon but I'm not clear what benefit would it be. Would you please let me know why you are using a starting semicolon, what benefit, or why it could be a good habit while coding?

    • @TEDCFPublishing
      @TEDCFPublishing ปีที่แล้ว +1

      Not sure about the semicolon either. It would be nice to know if it is a typo or standard practice.

  • @pouriyanourouznejad7090
    @pouriyanourouznejad7090 2 ปีที่แล้ว +1

    Ur the best 💜
    Can u pls teach us this 16:34 part with some examples?
    How to detect touchmove on swipe up/down/left/right ?
    For example, if I swipe up, then... (something happen)
    Need help to detect these moves 😅

    • @Italiafani
      @Italiafani 2 ปีที่แล้ว +1

      You could detect the direction by storing the `pageY` and `pageX` properties of the `Touch`es into variables and then comparing them to the updated values on later events. If previous X is less than current X, the touch is moving to the right etc. I can't be arsed to try this out, so I'm not sure if this works as is, but here's what I'd start with:
      const logDirection () => {
      // scope these variables so we can use this on different targets
      let prevX, prevY
      return (event) => {
      const { pageX, pageY } = event.changedTouches[0]
      if (prevX < pageX) console.log('right')
      else if (prevX > pageX) console.log('left')
      if (prevY < pageY) console.log('down')
      else if (prevY > pageY) console.log('up')
      prevX = pageX
      prevY = pageY
      }
      }
      document.addEventListener('touchmove', logDirection())

    • @pouriyanourouznejad7090
      @pouriyanourouznejad7090 2 ปีที่แล้ว

      @@Italiafani omg that sounds complicated, but thank you, I will try it 😅

  • @tobeyawaagwu1751
    @tobeyawaagwu1751 2 ปีที่แล้ว

    Is it there an event for double tapping?

  • @Jansa372
    @Jansa372 ปีที่แล้ว

    I'm creating a modal which on swipe down it closes. The issue is that with e.preventDefault() I can't focus on the element inside the modal because it prevents the click. Is there a work around this please?

  • @dailymeow3283
    @dailymeow3283 2 ปีที่แล้ว +3

    09:35 even if i put 3 fingers at once ... omg he's a cat 🐾🐈

  • @nathanbanji5015
    @nathanbanji5015 2 ปีที่แล้ว

    Can you please do a video on google maps api? I think it would be useful to a lot of people

  • @el_teodoro
    @el_teodoro 2 ปีที่แล้ว

    Can we do this too with iPhone?
    I don't use an iPhone myself, but I need to debug on it for clients...

  • @fractallabor
    @fractallabor 2 ปีที่แล้ว +4

    Why do you have semicolons before each .forEach calls? 17:28
    Edit: it was added magically at 9:25 by vscode I think 😆

    • @paoloose
      @paoloose 2 ปีที่แล้ว

      It's not needed there, but when you have a line that starts with brackets or parentheses, you must use semicolons at the start or in the previous line because otherwise the interpreter will think that line is a continuation of the previous line

  • @j0hannes5
    @j0hannes5 2 ปีที่แล้ว

    how would one detect the direction of a move?
    (eg. to trigger sth on a 3-finger swipe left gesture)

    • @CirTap
      @CirTap 2 ปีที่แล้ว +1

      you'd need to "cache" the initial taps' x/y coordinates and then compare them with those that trigger during the move event.
      Find any classic drag-and-drop tutorial for the trajectory bits. That should give you clues on how to implement that using touch events.
      Also anything that deals with geometries in JS such as "canvas" painting stuff could be useful.

    • @j0hannes5
      @j0hannes5 2 ปีที่แล้ว

      thanks. I'll definitely dive more into canvas stuff.
      For multi-touch-gestures, I'll use react-use-gesture. But I was surprised by this video, how straightforward the vanilla solution is.

  • @pawejakubowski829
    @pawejakubowski829 2 ปีที่แล้ว

    Hello Kyle,
    Thanks for great content.
    I don;t know why I can't run site on my mobile device. I'm on the same internet connection, the same IP adress. Did you come across that kind of situation?

    • @StevieB86
      @StevieB86 ปีที่แล้ว

      Did you ever figure out how to fix this? I'm having the exact same issue.

  • @MaxMov-sp8hr
    @MaxMov-sp8hr 2 ปีที่แล้ว

    Hello! Until 7:00 everything is fine. I press the button and further "it is not possible to get access to a site". Need help please.

    • @MaxMov-sp8hr
      @MaxMov-sp8hr ปีที่แล้ว

      I'm looking at it and it's working! Children's illnesses go away on their own ...

  • @YtResolver
    @YtResolver 2 หลายเดือนก่อน

    Hey Kyle unfortunately my doesn't work.
    Ive tried to navigate to my ip address on the phone but the pages aren't available.

  • @shapelessed
    @shapelessed 2 ปีที่แล้ว +1

    It's the worst when you're trying to have different handlers for click and touch...
    Then you remember touching also registers as a click...
    And yes, you can have both touch and click working on your computer, as long as you have a touch screen and your browser is aware of it.

    • @QwDragon
      @QwDragon 2 ปีที่แล้ว

      And you can plug mouse into the phone too ;)

  • @gugildak12
    @gugildak12 2 ปีที่แล้ว

    Thanks Kyle. I would use these tricks in my mobile apps developed with React Native(which is basically JScript😊) Maybe they documented already in Touchables.

  • @Deathrunify
    @Deathrunify 2 ปีที่แล้ว +1

    Is ;[] faster than Array.from() and Array.prototype.call.slice()?

    • @KenW418
      @KenW418 2 ปีที่แล้ว +1

      The semicolon is only there because of the interpreter. He doesn't use them on the end of each line. So the interpreter would consider those brackets to be part of the previous statement and execute it like an array (that wouldn't exist). To prevent this, he has to use the semicolon (delimiter) before the brackets.
      The [] is the "spread element" (look it up and read more). It can be used to create arrays from iterable objects. This is an important distinction with Array.from(). Array.from() can create arrays from iterable objects but also array-like objects (things with a length property, but may not be iterable). Neither of which is really faster than the other, but the way he uses the spread element wasn't necessarily what it's designed for. It also doesn't help the readability of your code. Array.from() makes sense to anyone who reads your code and should probably be used for this circumstance more than the spread element for that reason alone.
      The slice method is the old version of Array.from(). Array.from() is more efficient and can create arrays from more complicated data structures, but if browser compatibility is your concern then the slice method is your go to.
      Hope that helps!

    • @Deathrunify
      @Deathrunify 2 ปีที่แล้ว +1

      @@KenW418 thank you for this explanation, I appreciate it.

  • @Weizengass
    @Weizengass 11 หลายเดือนก่อน

    I lost it when I heard "we need two in the back"

  • @sfox-j
    @sfox-j 2 ปีที่แล้ว +1

    Five server which is a different extension automatically gives you the router address

  • @oluwatomisinbabatunde8426
    @oluwatomisinbabatunde8426 2 ปีที่แล้ว

    I couldn't have been the only one that saw those semi colons that are not needed

    • @CirTap
      @CirTap 2 ปีที่แล้ว

      @Maria it's also common for script concatenators and bundlers to put a semicolon between the scripts just to make sure statements don't "bleed" into each other.
      it's also a good idea to put one in front of any IIFE.

  • @janearnison
    @janearnison 3 หลายเดือนก่อน

    anyone get null error? I'm having a hard time fixing this.

  • @UnifiedFriends
    @UnifiedFriends 2 ปีที่แล้ว

    4:34 Knox 3.8: So you're using a Samsung, released on >= November 11, 2021.
    Fascinating how little it takes, to draw some kind of conclusions about something.

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว

      I am using a Samsung phone but it is much older than 2021

    • @UnifiedFriends
      @UnifiedFriends 2 ปีที่แล้ว

      @@WebDevSimplified Good to know that at least Business APIs/Frameworks get updates.
      Thanks for the feedback, I wasn't aware that Samsung provides updates for this component. Also for older devices, that may no longer receive system updates.

  • @salexkorsan8790
    @salexkorsan8790 11 หลายเดือนก่อน

    Brother please send me a code in js
    Tap on screen to execute function only once

  • @phonewebdevs3667
    @phonewebdevs3667 ปีที่แล้ว

    Is changedTouches an object?.... Am confused there

  • @mykalimba
    @mykalimba 2 ปีที่แล้ว

    5:38 Weird glitch that knocks video and audio out of sync.

  • @studywithali406
    @studywithali406 2 ปีที่แล้ว

    Plz give me heart