JavaScript Drag & Drop Sortable List Project

Поделиться
HTML-код
  • Опубликовано: 24 сен 2024

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

  • @TraversyMedia
    @TraversyMedia  3 года назад +86

    Yes, I know the order of people is not correct anymore 😅 This was made a while ago. Feel free to change the names/order

    • @Gameplay-fh1iv
      @Gameplay-fh1iv 3 года назад +3

      I could tell! You were using semi-colons😅

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

      How to make plugin like codemirror?? Plz make a tutorial on it🥰🥰🥰

    • @robotprogrammer2902
      @robotprogrammer2902 3 года назад +1

      you forgot elon musk

    • @ИринаБолотских-н3ш
      @ИринаБолотских-н3ш 3 года назад

      Hi!
      My name is Irina Bolotskikh, I am writing on behalf of Practicum by Yandex, Russia’s #1 practice-oriented and job-landing bootcamp. Designed by one of Europe's top tech companies, Practicum by Yandex offers guided courses in web development, data analytics, data science and UX/UI design. Each profession includes 24/7 support from our tutors and a free 20-hour intro course.
      We are very proud of our graduates who have already achieved so much (you can read their stories on Switchup and Course Report) and we would love your subscribers to learn more about it. Could you please suggest options for sponsored content at your channel?

    • @CristianRodriguez-zn4wp
      @CristianRodriguez-zn4wp 3 года назад

      @@Gameplay-fh1iv Many tutorials are still using it.

  • @jetzemeilink
    @jetzemeilink 3 года назад +72

    I just landed my first junior dev job today Brad! And your content has been a huge part of my learning. After I bought the javascript course I kept coming back to your videos and I still do. I thank you from the bottom of my heart and I hope you and your family are doing well.

    • @jennylin5563
      @jennylin5563 2 года назад +2

      wow, congratulations classmate, haha

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

      Yo happy for you pray to God to do mine.

  • @adnanalamofficial6432
    @adnanalamofficial6432 3 года назад +13

    Amazed!!! I was just practicing exactly like this project yesterday and now its explanation is on YT!
    Great work Sir Brad!!!

  • @Havii
    @Havii 3 года назад +29

    I really appreciate you sharing your knowledge and teaching skills with us

  • @abdurahmanyusuf5170
    @abdurahmanyusuf5170 3 года назад +7

    Sir I am first I am connected this youtube for years I am from somalia 🇸🇴 thanks brad

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

    This is by far the cleanest implementation of drag and drop I've ever seen 😍. Thanks for sharing this awesome technique, Brad🙂

  • @thesyd1982
    @thesyd1982 3 года назад +1

    thanks sir brad , I still follow your tutorials from the begin to the end , and i have real bad english you're just awesome

  • @Greg8872
    @Greg8872 3 года назад +2

    This is great, love how you step through things piece by piece. I always had to depend on a 3rd party script to do nested sortable items, but I love knowing the core base to do them myself.

  • @jjbudinski8486
    @jjbudinski8486 3 года назад +1

    Seeing classes that focus on the basics makes me happy, too many times there are multiple additional languages/systems that get slipped in right away which can be confusing.

  • @canerdemircigm
    @canerdemircigm 3 года назад +1

    The most useful thing in this video that I've learned is apply style all items in list except last item. Thanks a lot.

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

    Thanks for your videos. I have just purchased Build 20 mini frontend projects from scratch with HTML5, CSS & JavaScript course from Udemy. I will try to learn them all then come back to complete all your projects on RUclips.

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

    Thank you for this video! Saved me so many hours of trying to figure out how the drag and drop API works.

  • @marcosochieng5175
    @marcosochieng5175 3 года назад +6

    Thanks Brad. The best ever

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

    Thank you for this, I've been tearing my hair out on some tutorials, this is the first one that worked for me!

  • @xavelor
    @xavelor 4 месяца назад

    This was just what I was looking for! Thank you for sharing this.

  • @saeedsaleh6873
    @saeedsaleh6873 3 года назад +14

    Elon Musk rn: Depression, Sadness, Loneliness

  • @abhijith4252
    @abhijith4252 3 года назад +6

    Happy teachers day sir ❤

  • @TheCodeDealer
    @TheCodeDealer 3 года назад +3

    As always, Nice video Brad :))

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

    Thanks Brad! Your easy to follow solution helped me out a ton for a project that I am working on right now

  • @glitchspark1663
    @glitchspark1663 Год назад

    We can use Fisher-Yates to shuffle the array. That will be quicker.
    function shuffle(array) {
    const arr = [...array];
    for (let i = arr.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]];
    }
    return arr;
    }

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

    Really thanks for every tutorial you've been sharing with us! Every new content I either learn something new or review what I've learned. Your knowledge and skills about Front-end development are unique. Thanks again ;)

  • @andriiauziak1178
    @andriiauziak1178 3 года назад +2

    Hi Brad, thanks for new awesome video!
    Anyway I have a question. Why do you copying richestPeople array, even "sort" method is mutable it does not affect original array because it is called on new array of objects created by the "map" method?

  • @jeromesnail
    @jeromesnail 3 года назад +2

    I would have liked to know why we have to prevent the 'drag-over' default behavior.

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

    Today I was thinking of drag and drop featured project. Thanks a lot.

  • @YiannisChristodoulou
    @YiannisChristodoulou 3 года назад +1

    Thank you, Brad.
    You're awesome. Keep creating great stuff!

  • @wealthgenerationstrategies
    @wealthgenerationstrategies 7 месяцев назад

    Wow, this is truly an awesome tutorial. Learnt a few things about javascript that I didn't know! Let me ask a quick question if it's possible, how did you learn your ninja css skills? I'm sure there's an element of experience, but would you recommend any resources?

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

    Brad to the rescue! I have found great value in this tutorial.
    This is off the topic here...But I am wondering if you would ever do a tutorial on recursion in javascript. I have really struggled to get a hang of it.

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

    Brad we love you man, you a hero for us

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

    Congratulations to your birthday Brad!

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

    I really enjoyed this one. Looking at how to extend the functionality

  • @nocturnal7346
    @nocturnal7346 3 года назад +1

    I wonder what browser are you using? It looks really nice!

  • @abdellahdamri656
    @abdellahdamri656 3 года назад +8

    Thanks Brad !! Really Appreciate it , Keep up the hard Work !! I was wondering if u could make a Symfony Course in Details !!

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

    Very creative appoach to randomising list items with the two maps!

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

    Thanks for a very interesting, informative, and instructional video. As always, the code logic is very well explained.

  • @muhindokasukasilas3788
    @muhindokasukasilas3788 3 года назад +3

    Thx Brand you’re the beat 🤝🤝

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

    What's the best way to swap the cell you're using with ONLY the cell directly below it? Track the vertical (index) positions?

  • @hassaneoutouaya
    @hassaneoutouaya 3 года назад +3

    Thank you Sir !
    i'm just a little bit confused about how any changes occurs on the indexes of "list items" array, has to happen on "draggable list div" too, despite that there is no link between them.
    to precise i'm talking about how swapping items on "list items array" affect the "draggable list div" despite that i don't see any relation between them ?
    Thank you in advance !

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

      The list items array holds pointers to the list items that are children of the draggable list div. Thus, when the list items have their children swapped it will be reflected in the div. The list items 'themselves' aren't swapped.

    • @khaled-dev
      @khaled-dev 2 года назад

      Yes i'm also still very confused how does this work

  • @lukmanm5922
    @lukmanm5922 Год назад +1

    have a question. Why is appendChild(itemOne or itemTwo) not adding to the existing content of the .draggable class. That was the behaviour i was expecting. Did it just replace the existing content?

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

    Brad Brad.. I'm lucky to have you in my lifetime

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

    Nice Video. Really helpful for people wanting to learn JavaScript

  • @viniciusm.m.7822
    @viniciusm.m.7822 3 года назад +1

    Hi!!
    Would it be possible to "fix" the count of dragStart( ) event to 1 while been selected?
    My english isn´t that good, im sorry. I´m from Brazil, learning a lot from you, thanks!!!

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

    Much love from Jamaica.

  • @generationwolves
    @generationwolves 3 года назад +1

    An easier way to shuffle a list is to deduct 0.5 from Math.random() in the sort function.
    Example: [1, 3, 110, 40, 302].sort( ()=> Math.random() - 0.5 )
    - Math.random() generates random numbers between 0 and 1.
    - Deducting it with 0.5 can either generate a + number or a - number.
    - Passing the equation through the sort function will randomly place each item in front of or after the previous item, depending on the + or - value generated.
    Therefore, you can refactor your code without both the .map() functions under createList() with this.
    function createList(){
    [...richestPeople]
    .sort(() => Math.random() - 0.5)
    .forEach( ... )
    }

  • @SebastianPerezG
    @SebastianPerezG 3 года назад +1

    Will be nice if you can make a nested sorted list that will be nice .

  • @thingsiwishiknew8592
    @thingsiwishiknew8592 Год назад

    Great video , really helping me understand how to implement the drag events as I am currently trying to implement this functionality to a get endpoint, so I can sort the response and push through the values/order to a Db. Any suggestions as the list I have will be dynamic depending on where clause?

  • @thehijacker7
    @thehijacker7 3 года назад +1

    Regarding the sort function for numeric elements into an array, why the function that returns a - b, into the sort argument, makes the job done?

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

      The function gives you access to the current element and the next element. a and b. if you want the current element to stay in the current position (a), return -1, else return 1 and a will be moved the the next index. So by subtracting b from a you eighter get a negative or a positive number. In this case, if a is less then b, then you'll get a negative number, and only then would a keep its current position. But you could choose any kind of critaria for sorting, the clue is to return eighter a negative number or a positive one.

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

    Exactly what I was looking for, that's so much

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

    Very nice tutorial, thank you! I've built a little game from it and than realized that is doesn't work on touch-screens. Found some blog-posts how to identify touch screens and gonna try to fix it and load the appropriate event listeners . Just thought I leave that comment here .. mobile drag & drop could be worth an other tutorial.

  • @NoTalkUntilCovfefe
    @NoTalkUntilCovfefe 3 года назад +2

    I am confused. When the swapping items comes at around 40-45mins mark. He appendChild. In other words, adding an element. However, nothing is ever removed (unless I missed it at an earlier time). Why are they being swapped and not more children being appended over time? Does it have to do with the list[index] replacing one for the other? I didn't see any removeChild.

    • @hassaneoutouaya
      @hassaneoutouaya 3 года назад +1

      i think that because with "querySelector" method. all changes made by reference

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

      That's because one element (as javascript variable) cannot be in two places in one time.
      Try creating 2 divs, and create some other element like header in javascript code (assign it to a variable). Then append it to the first div in the first line (it's gonna be inside the first div). And then change the code, and add another line of code, where you append it to the second div (now it will disappear from the first div and be in the second div)

  • @au.voices
    @au.voices 10 месяцев назад

    thank you for made this tutorial. i was doing it. but i have a problem, it cant be work in touch screen. can you help me how to make this also work in touchscreen??

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

    Hey Brad, wondering if you can do a video on Angular unit testing ? Couldn’t find anything nice on the internet. Thanks!

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

    Your Tutorial is so amazing helpful for me, thank you so much...^^

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

      I implemented something similar to this and also added swap, add and delete functionality along with drag and drop. Have a look and lemme know if you liked it.
      ruclips.net/video/AAmx-WWKCKM/видео.html

  • @priyanka_kofficial6579
    @priyanka_kofficial6579 Год назад

    Hi...Can you plz show with kendo ui...how we can draggable dropdownlist option

  • @smarts7967
    @smarts7967 7 месяцев назад

    Thanks, how could you drag multiple?

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

    should use grab cursor instead of pointer cursor for dragging (personally thought)

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

    How would you add a individual image to a name, say a photo of that person rather than the grab handles? I tried adding to the background using li:nth-of-type(1) and li:nth-of-type(2), etc adding one for each person. But obviously they do not drag when the li is moved. Any ideas?

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

    what about saving the results so that when you refresh or load the page it remembers the new sort order?

  • @KT-ib3eq
    @KT-ib3eq 3 года назад

    Thank you for always providing us a great learning project like this. Your videos make me motivated.

  • @Jean-yk9eo
    @Jean-yk9eo Год назад

    Can someone explain the 42:42 - 43:11 line? I know what that line does, but I am not sure how it works.

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

    Today, I am doing a task with pspdfkit, the client require me to drag and drop pages in the thumbnail to change the order of pages in pdf files. Suddently I seen this video!!!

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

    How can I test the drag effects with my console window open? I can't see all the drag functions (I mean the console outputs to test to see dragover, dragenter, etc.) working in real time if I use chrome developer tool. With fire fox I can see the drag functions working, though. There should be a setup that I need to change in Chrome. so does anybody know about it?

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

    as i have tested its not working with mobile device can you pleas help in that ?

  • @khaled-dev
    @khaled-dev 2 года назад

    44:53 I don't understand how can you use DOM Element Object methods like appendChild on a JavaScript array and it reflects on the DOM?

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

      by using array, that specific element is grabbed,
      use console.log , u will understand what he is doing

  • @andrewclarkemusic8570
    @andrewclarkemusic8570 3 года назад +1

    can anyone explain how that sort worked??

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

    Thanks! Any thoughts on how to make this work on mobile? The dragging doesn't seem to work for me so far.

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

    @brad a question: i got very limited knoledge about back end and its not really what drives me. im know very good my ways around javascript and DOM manipulation, html, css, and consider myself gsap animations wizard,and im currently learning webgl,i can recreate any interface from wwwawards so i have this friend that work for 20 years doing sotware using oracle azure but with very limited experience on front end, we trying to make a start up /web agency and what is holding us i feel is to find a way to marry the 2 sides to produce any software,website or webapp we need, so the question: if you were in my position what would you spend your time learning? SQL?react/next js or something else? thanks for the content , sorry for the english its because im so desperate for an insigh on this that i asked the same question to multiple dev related youtubers i respect, thanks for the content ,its super helpfull as aways

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

    How to make the welcome page in new tab like yours ?

  • @keremardcl6759
    @keremardcl6759 Год назад

    How can we re-sort the list rather than swapping positions?

  • @morningstar-1112
    @morningstar-1112 3 года назад

    Really Amazing, Thanks

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

    Why are you SWAPPING the elements around? I see that this is easily achieved but it's not really convient when you really want to order anything manually.
    When would swapping be needed? When moving item 4 to position 1 your code puts item 1 to 4 instead of 2 .. when would you want this kind of functionality.
    I don't get it.

  • @aryanmishra3136
    @aryanmishra3136 3 года назад +1

    Hey, Brad please make a video on audio pitch detection and processing on web (cross-platform, if possible)... Will be very helpful

  • @ganeshkharat009
    @ganeshkharat009 Год назад

    I want to mobile drag drop in javascript how can i do?

  • @AbdoTech0
    @AbdoTech0 3 года назад +2

    First🔥❤️

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

    Can someone tell me what i need to know to get my first job as a Junior Front Dev? I know how to do basic stuff like creating simple games in Canvas, ToDoLists, Animated Navbars and i m right now trying to learn Async Await, where is the point when i will be good enough to apply for jobs, i just hate doing things when i don't know when there is that minimal cap.

  • @safwanu2be
    @safwanu2be 3 года назад +1

    Hi bro, hope you are doing well ☺️

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

    De-mystifying drag excellent

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

    How if you drag with more pages on the list? Any ideas?

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

      Ofc no answer to this.

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

    Thanks very useful!!

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

    Hi! Can you give me a FYP idea for the android app

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

    you are the best, thanks

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

    Brad Can you do a trello clone using react js

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

    I built drag and drop functionality in pure JS. I didn't do the sortable components though... :/

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

    Awesome video Brad! Any chances for a mobX react tutorial ? Cheers.

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

    Thanks Brad

  • @pikboi956
    @pikboi956 Год назад

    how to delete drag?

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

    Thx so much!

  • @Ameersoccerdev
    @Ameersoccerdev 3 года назад +2

    Who are those developer who watch travesy toturial and download as well

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu Год назад

    thanks

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

    Tank you Brad!

  • @czesislawadam8979
    @czesislawadam8979 4 месяца назад

    Super 😎

  • @Duesenberg-n1h
    @Duesenberg-n1h 3 года назад +1

    good👍🏽

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

    do this in react as well please!

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

    Nice

  • @Duesenberg-n1h
    @Duesenberg-n1h 3 года назад +1

    good

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

    awesome

  • @0503trang
    @0503trang 3 года назад +1

    too hard for me :D

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

    Nice🤗

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

    There is that meme lord ?

  • @Ameersoccerdev
    @Ameersoccerdev 3 года назад +2

    First

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

    Hey Brad can you try this in angular