Drag & Drop With Vanilla JS

Поделиться
HTML-код
  • Опубликовано: 21 май 2018
  • In this video we will take a look at drag events in JavaScript to be able to create drag and drop functionality
    Code:
    codepen.io/bradtraversy/pen/o...
    💖 Become a Patron: Show support & get perks!
    / traversymedia
    Website & Udemy Courses
    www.traversymedia.com
    Follow Traversy Media:
    / traversymedia
    / traversymedia
    / traversymedia
    The Developer Hangout: Public Discord Server
    / discord
  • НаукаНаука

Комментарии • 407

  • @TraversyMedia
    @TraversyMedia  6 лет назад +56

    I forgot to mention I do have a 21 hour course on vanilla JS on Udemy if anyone is interested here is a $10 code.
    www.udemy.com/modern-javascript-from-the-beginning/?couponCode=RUclips10

    • @jolyonfavreau3160
      @jolyonfavreau3160 6 лет назад +2

      bought it and have been working through it slowly. excellent course, full of easy to follow content.

    • @hossameldinshaheen5366
      @hossameldinshaheen5366 6 лет назад

      Are you will make react course i mean react front to back like angular not the course that you explain projects, please we need essential course with projects.

    • @slinco65
      @slinco65 6 лет назад

      Working through it now - great course Brad! Anyone who wants to _really_ know javascript should take Brad's course ;-)

    • @dadev3668
      @dadev3668 6 лет назад

      Definitly a great course I just got past the ajax part and it's great I can finally do some kool apps with my laravel backends, I do have one request for once if you can get a chance to do a tailwind css course that would be great Thanks Brad

    • @albertgalvez2556
      @albertgalvez2556 6 лет назад

      Got it and can't wait to go through it.

  •  6 лет назад +79

    Hi. Thanks for an amazing tutorial as always! I would do two improvements to this code:
    1. requestAnimationFrame() instead of setTimeout()
    2. classList.add() & classList.remove() instead of manipulating className string
    Thanks again! Keep on doing amazing work!

    • @coced
      @coced 5 лет назад +9

      classList.toggle is pretty neat too

    • @icarofilho6524
      @icarofilho6524 2 года назад

      I just used requestAnimationFrame and it works great thank you.

    • @Maxim9575
      @Maxim9575 2 года назад

      About rAF that function works on similar principles like setTimeout, but there is one thing which change everything. setTimeout based on queues executed codes (rude but it is), every setTimeout in running code is set at the end of such queue, and when queue will come to the next setTimeout, that setTimeout will be execute. rAF practically is same, but it will be invoked also like setTimeout but with one optimization thing, it's synchronization with HZ of your display. So rAF may be called faster than setTimeout or against slower, it all depends on your monitor mostly.
      You should see lecture about Event Loop or Jake Archibald: In The Loop.

  • @MrThejhubs
    @MrThejhubs 4 года назад +2

    I gotta say, as far as content, this is one of the best tuts I've watched. You described the topic of the video (drap & drop & their listeners) on a basic level without going into every single other feature you were using (callbacks, timeouts, etc.). A simple thing, but my biggest complaints on other tutorial channels. I came here to learn drag and drop, and I did. Thank you, subbed.

  • @scorpionesp6510
    @scorpionesp6510 2 года назад +1

    Bruh, I love your teaching style, and how you are so clear and how you show how things work instead of just watching you code. Purchased a bunch of your courses to support and subscribed (yes aiming for a cookie here) but love your lessons and thanks!

  • @glenn_r_frank_author
    @glenn_r_frank_author 4 года назад +3

    Thank you for such a complete tutorial for basics and beginners on this. I love how you took the time to show us the consolw events firing off .. really made it so much more understandable!

  • @mohammadakbar32
    @mohammadakbar32 6 лет назад +72

    i was looking for drag n drop! thanks Brad! God bless you and your family

  • @hardikmodi8234
    @hardikmodi8234 6 лет назад +17

    Whenever I think of implementing something in project, on the very next day sir Brad have Video on that. Really amazing. Thank you very much for your great efforts.

  • @wesstephenson4533
    @wesstephenson4533 5 лет назад

    I wish more people taught like you do. You not only make sure I understand, but you explain things in a way that I can't misunderstand. I love it!

  • @jopeme_official
    @jopeme_official 3 года назад

    Your videos don't get more helpful than this. Thank you so much for not only teaching us this but do it in a way that ANYONE can understand. Truly appreciate you, man!

  • @mn6210
    @mn6210 6 лет назад

    Thanks for the free drag and drop tutorial. Whenever I need something related to programming language , first thing comes to my mind is this channel(traversy media). Your channel is in top of my list. I appreciate your work..

  • @Jadraptor
    @Jadraptor 6 лет назад

    Thank you for doing these sorts of videos. It makes it easy for me to learn at my own speed.
    This was also not nearly as complex as I thought it would be. I have a new understanding for how to structure such things in vanilla.

  • @arpanmukherjee4625
    @arpanmukherjee4625 6 лет назад +26

    Love this channel....I have learnt Laravel, Vue.js, Building REST Service and what not....Best of the best.....

  • @nick.karimi
    @nick.karimi 6 лет назад +29

    These new videos can be overwhelming, I am trying to stick to learning just a few web development languages that fit within my schedule but EVERY pop UP notification from Brad, are irresistible.. There is a new thing to learn or a word for motivation to upcoming developers..Thanks Brad, You the best.

    • @TraversyMedia
      @TraversyMedia  6 лет назад +9

      I realize that. What I always suggest is having a core set of technologies that you REALLY dig into and learn through various resources BUT it does not hurt to watch and learn other things just to grasp the coding concepts, etc. A lot of time it will help you in just general logic and understanding in programming in general.

    • @nick.karimi
      @nick.karimi 6 лет назад +3

      Traversy Media Thanks a bunch, you always a source of my Motivation..

    • @raymondmichael4987
      @raymondmichael4987 6 лет назад

      Great point Sam C

  • @tonniewhiteley2497
    @tonniewhiteley2497 6 лет назад

    You know I was on the train home yesterday dead tired and I went on RUclips to watch some chill videos and I saw that one and I got sooo excited that even after a whole day of work I had to watch this :D thanks Brad :)))

  • @Navarragirl27
    @Navarragirl27 4 года назад

    The one and only Brad, who can explain JS so well anyone can understand. Thank you very much :)

  • @arturluisoliveira
    @arturluisoliveira 4 года назад

    thanks brad, I've studied javascript in your channel for a while and recently at my first task end up in here again! hahaha. thanks for the knowledge, happy new year.

  • @LordN3r3v4r
    @LordN3r3v4r 6 лет назад +14

    domElement.classList.toggle('hovered'); Way easier to understand and the support is there (for IE), as long as you use just one parameter (the class name string). There are also .add(), .remove(), .contains() and .replace() methods for dealing with CSS classes. Nice video!

  • @expchrfir
    @expchrfir 5 лет назад

    im doing my first js applicationa and you have some great content. not the first time this week im ending up with a video of yours. Cheers!

  • @daalwada
    @daalwada 2 года назад +1

    Basics of Kanban board 😅 Amazing work Brad! I am really glad there are developers like you who exist to contribute genuinely to teach people! Great tutorial 😊👍

  • @AdegbengaAgoroCrenet
    @AdegbengaAgoroCrenet 6 лет назад

    This is a great tutorial. I would traditionally implement this with a library but now I am definitely going to be doing pure Vanilla for these. Thanks Brad

  • @gavincoulson3900
    @gavincoulson3900 3 года назад

    Brad I cannot tell you how much I appreciate your videos. Please keep making this amazing content. Love your channel and love your Udemy courses.

  • @eoussama
    @eoussama 6 лет назад +5

    You never fail to amaze Brad, splendid tutorial, god bless you and your family, keep up the hard work 👍.

  • @juditzentai1517
    @juditzentai1517 4 года назад

    This video is very helpful. I just want to mention that I used a different solution to see only 1 picture while being dragged, under the cursor and not on the original place. I simply added to the . hold in the CSS an opacity: 0% attribute. This way while the picture is being dragged, the original picture in the original place becomes invisible. This might not be the most elegant solution but you do not have to use setTimeout().
    Anyway, you just shortened my home assignment a lot so thank you! :)

  • @limitless9483
    @limitless9483 4 года назад

    As someone who hasn't started learning frameworks yet, this helps me a lot, will implement it in my js game, thanks brad.

  • @joduaxddddd
    @joduaxddddd 6 лет назад +2

    I've been looking for this for the past few days

  • @mihkelsiim761
    @mihkelsiim761 4 года назад

    These console messages were really useful. It helped me a lot to understand when what is run.

  • @cyt4638
    @cyt4638 3 года назад

    Awesome tutorials for drag events in front-end design! Thank you Brad!

  • @theWanAndOnly
    @theWanAndOnly 4 года назад

    man, javascript has advanced over the years. It's really intuitive and easy to do all these complex things now. Hooray for progress! And thanks for your tutorial btw, making it look effortless is not easy, you're doing it good man.

  • @jamalabdullahi8155
    @jamalabdullahi8155 6 лет назад +2

    Many thanks brad this is what I was trying to do this week

  • @myhandle370
    @myhandle370 2 года назад

    Short video and straight to the point. Excellent!

  • @leoniduvarov6565
    @leoniduvarov6565 5 лет назад

    I'll be using this for my final project at my internship. Thank you!

  • @stephh4392
    @stephh4392 6 лет назад +1

    Another high quality video!!! I learned so much updated JS from you, thank u, sir^_^

  • @K8Tech
    @K8Tech 6 лет назад

    You struggle searching how to do something with your app... Brads got you.
    Thanks man!!!

  • @zachbaird2851
    @zachbaird2851 6 лет назад

    I saw this on my RUclips dash and said "Yeeeeeees". Love the tutorials, Brad!

  • @xenialxerous2441
    @xenialxerous2441 6 лет назад

    Hey Brad! I can't thank you enough for sharing your knowledge & helping others achieve their goals.. thank you so much. I wanna be one of your Patron in a near future!!

  • @steveymcneckbeard
    @steveymcneckbeard 6 лет назад +1

    Oh Brad you do make my day, thank you so much for all your hard work!

  • @WinkkleBoss28023
    @WinkkleBoss28023 5 лет назад

    Thank you, sir.
    because of you, I was able to learn HTML, CSS, js and bootstrap in my summer vacations.
    god bless you and your family.

  • @vovaparkhomchuk
    @vovaparkhomchuk 6 лет назад

    You are the best Brad! Thank you very much. Every time I watch your videos, I learn something new, simple and (that is important) very interesting

  • @fogreyiz
    @fogreyiz 5 лет назад

    Excellent tutorial without unnecessary and complicated details.

  • @rohitdalal954
    @rohitdalal954 6 лет назад

    Awesome tutorial :). I was thinking of doing it yesterday and you made it easier! Thanks:)

  • @gorki90
    @gorki90 6 лет назад

    Great video. It's incredible how you keep doing videos explaining things I would need to look up in near future.

  • @michaeljfordham
    @michaeljfordham 5 лет назад

    Really, really great video and in-depth explanation. Thanks for sharing Brad!

  • @canimcanimnazlim
    @canimcanimnazlim 2 года назад

    i love the way you try to make us understand whats going on really :)

  • @misterz5908
    @misterz5908 3 года назад

    Please Brad can you do more this kind of short and very useful courses !🙏
    And Thanks a lot! We love you💕

  • @AetherXIV
    @AetherXIV 3 года назад

    your tutorial style is excellent. thank you so much man. clear and easy to follow

  • @VeeWebCode
    @VeeWebCode 6 лет назад +16

    Sir, your tutorials are so awesome..

  • @lucasa8710
    @lucasa8710 3 года назад

    this is the best video i have ever seen, i mean, the way you explain it is really amazing; sorry about my english.

  • @LesAnimes
    @LesAnimes 5 лет назад +1

    Man come on!!! you make everything look extremely easy, you are the one, God bless you

  • @kingundfaker
    @kingundfaker 5 лет назад

    14:08 You can mark the lines you want to copy and then shift+alt+arrow key to instantly copy&paste.
    Nice Guide on Drag & Drop! You helped me implenting this on my Dungeon & Dragons Browser Game :)

    • @TraversyMedia
      @TraversyMedia  5 лет назад

      Thanks, yeah I learned that a bit after this video :)

  • @abdelabdel8089
    @abdelabdel8089 5 лет назад

    I can not thank you enough man. You are saving my day almost everyday!

  • @lorgaraurelian1480
    @lorgaraurelian1480 5 лет назад

    Thank you, man. A very good introduction to drag&drop event.

  • @erayeroglu8175
    @erayeroglu8175 6 лет назад

    Your pronounciation and expression is very clear, I can easily understand you. Thanks bro

  • @Yiosho
    @Yiosho 6 лет назад

    Wish I could've had this video some months back when I had to do this at my first job... In the end had to settle using jQuery. Really nice video, thank you!

  • @calvinrosehart7042
    @calvinrosehart7042 4 года назад +1

    Great job explaining everything, very much appreciated!

  • @Soumya21st
    @Soumya21st 6 лет назад +10

    Brad is a Javascript Rockstar in the youtube earth

  • @khudoyorrakhmatov7530
    @khudoyorrakhmatov7530 2 года назад

    The way Brad delivers content is next level. After having watched his videos for some time, I became a picky learner.

  • @sulpher9
    @sulpher9 6 лет назад

    Appreciate the explanation of what is going on - good stuff!

  • @Mental1993
    @Mental1993 6 лет назад

    Amazing work once again.
    I also support you on Patreon. Never regret a single dollar spent.

  • @aayush_dutt
    @aayush_dutt 6 лет назад +1

    I love this channel

  • @kps2642
    @kps2642 6 лет назад

    thanks man , always surprising us with something new :)

  • @lucasbertoldo5062
    @lucasbertoldo5062 3 года назад

    Exactly what I was looking for. Thanks, Brad, for save me one more time!

  • @carlotadias9335
    @carlotadias9335 2 года назад

    Amazing explanation and very simple and direct! Thank you!

  • @PlotTwists
    @PlotTwists 6 лет назад

    Nice video very clear and simple and strait to the point, keep up the good work

  • @hemaethossain4946
    @hemaethossain4946 6 лет назад +7

    Love you Brad. You're a nice guy!

  • @MikeMansourTech
    @MikeMansourTech 4 года назад

    Thank you Brad! Saved me a bunch of time, amazing!

  • @n_fan329
    @n_fan329 5 лет назад

    Brad Traversy !! I love you brother from the bottom of my heart, you really changed my life :)

  • @Sjongleringsmannen
    @Sjongleringsmannen 4 года назад

    Thanks for a very nice video on dragevents! I loved it!

  • @gowthams8340
    @gowthams8340 6 лет назад

    *Amazing Brad ! Hope more js videos coming*

  • @davillesinteriors
    @davillesinteriors 5 лет назад

    You are the best man, simply the best. Your tutorials have so much helped me especially for Vanilla js. Thanks and
    God bless You

  • @blacklotus1606
    @blacklotus1606 6 лет назад

    to be honest amazing tuts, i was looking for something like it..., and the console.log explanation was top notch.

  • @ancholicbhai5100
    @ancholicbhai5100 4 года назад

    Great tutorial.
    Really helpful, thank you so much Brad!

  • @GabrielSantos-gp9yw
    @GabrielSantos-gp9yw 4 года назад

    Man, you've saved me! This tutorial was awesome!

  • @TheSakyun
    @TheSakyun 6 лет назад

    Love your videos brad, keep it up !

  • @jatinraj4974
    @jatinraj4974 6 лет назад +21

    Love your work sir 😍 . Now I am 14year old and learned js and done few projects just because of you .You gave me love for coding thanks sir .😊

    • @TraversyMedia
      @TraversyMedia  6 лет назад +5

      That is awesome. I wish I got started that young. Keep that up and you'll run circles around other devs when you're older

    • @PlotTwists
      @PlotTwists 6 лет назад

      you swapped your age numbers ... it's 21

    • @jatinraj4974
      @jatinraj4974 6 лет назад +2

      Male Man what to say ..haters come every where .You do your work I will do mine.Thanks 😊😊😊😊

    • @jatinraj4974
      @jatinraj4974 6 лет назад

      Traversy Media thanks for this advice sir 😊 love for code😋

  • @nordy2010
    @nordy2010 6 лет назад

    Well done! Very concise and informative!

  • @RufusVidS
    @RufusVidS 4 года назад

    Terrific tutorial as usual. The only one comment I felt was missing was the fact that the .append() method removes the element from its prior container automatically (which is clear as you watch the elements in the Developer Tool window), but I remember wondering why there wasn't a remove() method to detach an element from the original container.

  • @hanschannel599
    @hanschannel599 6 лет назад

    perfect tuts Brad (as always)!

  • @josuedanielflores2008
    @josuedanielflores2008 5 лет назад

    Another great tutorial, thanks Brad!

  • @4konung
    @4konung 6 лет назад

    This is great tutorial! Thank you Brad.

  • @kuvinci
    @kuvinci 5 лет назад

    *Awesome!* I was struggling to do good drag&drop on es5 but it's so much easier on es6

  • @agustinlavalla8892
    @agustinlavalla8892 4 года назад

    Very instructive and useful. Thanks!

  • @Chintmaster
    @Chintmaster 6 лет назад

    Found this channel today. Subbed.

  • @saikumardesu1700
    @saikumardesu1700 2 года назад

    Thank you very much for sharing, exact video I was looking for.

  • @quechon1
    @quechon1 6 лет назад

    Im a python guy but with your videos i have learnt a lot thanks for the time youbput on this man

  • @fev4
    @fev4 6 лет назад

    Thank you Brad! Awesome as always

  • @lukasdemmer1605
    @lukasdemmer1605 5 лет назад

    very good video and explanation, i found what i searched for

  • @TruthSeekerClub
    @TruthSeekerClub 3 года назад

    very simple and neat

  • @birsingh5388
    @birsingh5388 6 лет назад

    Just buy your Vanilla JavaScript course, I hope I will learn lots of new things from that udemy course. Thank you, Brad.

  • @FelipeVercingetorix
    @FelipeVercingetorix 6 лет назад

    You are amazing. This is so much helpful. Thank you!

  • @Zibinskiy
    @Zibinskiy 5 лет назад

    Брэд, ты классный специалист! Спасибо )))

  • @mr.c7411
    @mr.c7411 3 года назад

    Best programming channel🙌

  • @user-ff2et9rx5l
    @user-ff2et9rx5l 3 года назад

    Your tutorials are awesome!

  • @jaimin_marfatia
    @jaimin_marfatia 5 лет назад

    Nice and informative.. Thanks Brad! Love your content..

  • @MrPDTaylor
    @MrPDTaylor 5 лет назад

    Loving you intro to JavaScript Udemy course right now!

  • @snowman_web_design_development
    @snowman_web_design_development 4 года назад

    Awesome, this gave me great ideas, thanks Brad, u rock!

  • @Haresh1270
    @Haresh1270 2 года назад

    Fantastic, this is what I was looking for

  • @nahabiz
    @nahabiz 6 лет назад +1

    Great tutorial, as always, Brad. Could you do a part 2 where all the divs are filled but if you pick up an image from one div, and drop it on another filled div, the image from the first div replaces that from the second div. On drop, the image from the second div, would move to the now empty first div. I hope this make sense.

  • @KcKc-bh6lu
    @KcKc-bh6lu 5 лет назад

    Wow, this's much easy than when I implemented drag and drop over ten years ago!

  • @euphaniegrace3020
    @euphaniegrace3020 6 лет назад

    Awesome video! Thanks Brad :)

  • @deryckoe84
    @deryckoe84 5 лет назад

    Thanks, Brad. Great video!