Draggable Div Element in HTML CSS & JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ต.ค. 2024
  • Draggable Div Element in HTML CSS & JavaScript
    In this video, I have shown you to create a Draggable Div Element in HTML CSS & JavaScript. You can move this div element anywhere on the document or page.
    Live Demo or Download Codes of this Draggable Div - codingnepalweb...
    My Code Editor - • Best Text Editor for H...
    Facebook - / coding.np
    Instagram - / coding.np
    Music Credit:
    Ikson - Last Summer [Official]
    • #37 Last Summer (Offic...
    Track: Ehrling - You And Me (Vlog No Copyright Music)
    • Ehrling - You And Me (...
    Track: Jimmy Hardwind - Want Me (feat. Mike Archangelo)
    • Jimmy Hardwind - Want ...

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

  • @CodingNepal
    @CodingNepal  3 ปีที่แล้ว +9

    Live Demo of this Draggable Div - codingnepalweb.com/demos/draggable-div-element-in-javascript/

  • @jeenitprajapati3449
    @jeenitprajapati3449 3 ปีที่แล้ว +4

    Wow!!! Amazing, A Draggable Div Element. Thats Great! THANKS SO MUCH CODING NEPAL

  • @COFFY_GAMING
    @COFFY_GAMING 3 ปีที่แล้ว +5

    Sir really it's awesome thanku sir for chat application my college project is ready, thanku so much for all content on TH-cam 😘

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

      Glad to hear that 😊

  • @vladgonzaleza8774
    @vladgonzaleza8774 ปีที่แล้ว +11

    Using top and left is to change the element's position is not ideal since it triggers a screen re-write. Instead, you should use transform() as it does not require the browser to re-write the element, it simply applies an aspect transformation using the GPU.

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

      Can you please help with a tutorial for transform

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

      Thanks mate, saved me 9 minutes, was afraid it's not transform

  • @roxiejain6221
    @roxiejain6221 3 ปีที่แล้ว +5

    I can't believe that you just explained easiest and simplest way to do that. 🤩🤩 Thanks Bro 😎

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

      You're welcome bro and don't forget to watch my other videos.

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

      @@CodingNepal Definitely 👍😇
      The way you set up your video thumbnail. 📹
      that shows your passion, your dedication, your skill. 👨‍💻
      I haven't seen such simple and minimal (HTML, CSS, JS) tutorials anywhere on TH-cam. 😍
      Your videos prove to be very helpful in my project (making react components). 😇
      Keep it Bro 👍😎✨❤

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

      @@roxiejain6221 Many many thanks to you. I really appreciate it 😃

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

      @@CodingNepal you explained it better than w3 schools and the mdn. Your content was straight to the point. Thanks man.

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

    हजुरको काम धेरेे राम्रो छ दाई येस्तेे भिडियाहरु राखिरहनु। हजुरको भलो होस्। Love From Nepal

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

    Thanks. You saved my day. I implemented this with someone else's code. However margin-left creating mess. Using just left property of div worked to position div in the beginning as you shown. Thanks once again.

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

    Just awesome❤️🔥
    NEPAL 🇳🇵✌️

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

    Can you make dragable list to put another div using drag

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

      I'll think about it.

  • @CreativeTutorialsWeb
    @CreativeTutorialsWeb 3 ปีที่แล้ว +5

    Great content once again Sir exactly what I needed

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

    Omg,this is so nice sir! Superb work😊

  • @oladipupoakorede
    @oladipupoakorede 3 ปีที่แล้ว +5

    i love this

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

    Mannnn... That's very nice 😉👌, im really like it!!!

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      Many many thanks 🔥

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

    amazing bro

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

    Great Content Brother 🔥🙏

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

    from where you get such amazing ideas....!🤘

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      It's all about experience.

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

      @@CodingNepal Great..!👍

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

    I love this!! ❤️ How do you make the div move only inside the límits of the screen?

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

    this is exactly what i was looking for thank you

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

    4:30, starting with the move script

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

    Sir please make a video on pagination with bootstrap 5 and php, with ajax and without ajax

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

    Sir , we need shopping cart with JavaScript and local storage and contains..sign up .. sign in.sign out ..add to favorites..add to cart..profile for user..admin page to add product etc..and page notification for admin to know the user who bought the product ..filter and search for product ..
    Please ..please do it for us we wait you ..thanks sir ..❤️

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

    Awesome bro 😍😍 waiting for your voice

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      I'm thinking to add voice in my videos after 100k if possible.

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

    Great project so useful 👌

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

    omg this was stupidly simple. thank you I don't need to use libraries

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

    One day you will cross 1M

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

      Hope so. Keep supporting.

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

    Awesome 🔥

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

    Thanks For Uploading. ❤️

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

    I was in need of this, very thaaanks

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

    Bro can we fix wrapper div after dragging it to a different position through mouseup event.
    Btw Great Video Brother 🔥🙏

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      Sorry bro, I didn't understand. Can you please explain more?

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

      @@CodingNepal bro i mean to say that drag though whole wrapper div .. not only header
      I tried but there's problem

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

      @@jatinsharma5859 Remove all the codes which are inside tag and paste the following codes.
      const wrapper = document.querySelector(".wrapper");
      function onDrag({movementX, movementY}){
      let getStyle = window.getComputedStyle(wrapper);
      let left = parseInt(getStyle.left);
      let top = parseInt(getStyle.top);
      wrapper.style.left = `${left + movementX}px`;
      wrapper.style.top = `${top + movementY}px`;
      }
      wrapper.addEventListener("mousedown", ()=>{
      wrapper.classList.add("active");
      wrapper.addEventListener("mousemove", onDrag);
      });
      document.addEventListener("mouseup", ()=>{
      wrapper.classList.remove("active");
      wrapper.removeEventListener("mousemove", onDrag);
      });
      Now go to the css file, line.no 28, there is a .wrapper header.active replace this line with this .wrapper.active

    • @jatinsharma5859
      @jatinsharma5859 3 ปีที่แล้ว

      @@CodingNepal are ty bro for this much effort 🙏🖤

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

    Hey. What would be a real world example of this feature or ability?

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      It can be used on desktop softwares/applications.

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

    nice tutorial , but , this has a side effect . If you move the mouse fast enough , the header will lose listener , you have to refresh the page , that is annoying

  • @Noobgamer-qe4gv
    @Noobgamer-qe4gv 3 ปีที่แล้ว +1

    Super

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

    We are expecting one complete ecommerce website sir..

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

      Okay, I'll think about it.

    • @sudhagars641
      @sudhagars641 3 ปีที่แล้ว

      @@CodingNepal thanks for your reply sir

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

    Hey ! This was great tutorial. Please suggest me over this problem : i want to make them draggable only inside parent element it should not be dragged outside of parent element

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

      @@yt_brij huh...
      not working

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

    Sir when will the article come on Instagram photo and video downloader website
    Love from India ❤❤

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      I'll think about it. Keep visiting my site for more other helpful blogs.

    • @roshanshaw7742
      @roshanshaw7742 3 ปีที่แล้ว

      @@CodingNepal Sir Please Write an article as soon as possible thank you, sir

  • @m.s.4854
    @m.s.4854 3 ปีที่แล้ว +1

    Can you make level system? Like if you do something, you gain xp and when you have like 100xp, you level up to the first level, then you need to have 200xp to level up again and etc. I think it'll be super interesting to make and use.

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

    Pc specification please?

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      CPU - Ryzen 3 3300x
      Motherboard - MSI B450M Pro
      GPU - Nvidia GTX 1650 4gb
      Ram - Tforce RGB 8 * 2 = 16GB
      Hard disk - 500GB
      SSD - 256GB

    • @atiffattah1984
      @atiffattah1984 3 ปีที่แล้ว

      @@CodingNepal Thank you.

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

    Bro Can you Please make video on "How to make a custom QR code generator in PHP"?????
    I will be waiting for your reply!
    OKkkkkkkkkkkkk........

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

    sir How can i get latitude and longitude by giving address manually ?

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      I didn't understand. Please explain more.

    • @atanujana8119
      @atanujana8119 3 ปีที่แล้ว

      @@CodingNepalif i type my address on form , after submit api will fetch latitude and longitude according to my address,

    • @atanujana8119
      @atanujana8119 3 ปีที่แล้ว

      And tell me how to use google map api

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

    Op bro.😘😘😘

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

    I love it

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

    thanks bro i appreciate it

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

    Cool bro

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

    How to stop div dragging using button

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

    perfect tutorial !
    I love your videos ! 🌺🌹
    can you make this draggable div drag with mouse and touch?🙏
    It doesn't work in mobile

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

    Perfect
    Can you learn to make line graph only html and css and javascript?
    Please please please

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

      Can you explain more?

    • @lucaslopes8701
      @lucaslopes8701 3 ปีที่แล้ว

      @@CodingNepal of course 😄
      A line graph (not using graphics libraries), if possible only with html and css, otherwise canvas or svg

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

    Nice

  • @creadoz_
    @creadoz_ 6 หลายเดือนก่อน

    What if i want multiple of those?

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

    @CodingNepal, Can I Ask You Something? Is There We Can Get The Local Storage Of Where The Draggable Div Element Was? So Suppose I Last Dragged The Element On x = 43 and y = 26, Can We Get The Local Storage Of That So The Next Time The User Reloads That Page, The Element Will Be In Those Coordinates?

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      Yes, you can store the element x and y positions to localStorage of the browser and retrieve it.

    • @ShushanandIvan
      @ShushanandIvan 3 ปีที่แล้ว

      @@CodingNepal Can You Make A Short Video Of You Doing It Please? I Cannot Figure Out How To.

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

    its not working in touch screen device what is the solution

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

    Purple is your fav color

  • @cwansu5112
    @cwansu5112 3 ปีที่แล้ว

    Sir How to create Text editor using javascript, css, html, jQuery

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

    Op

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

    It not works in mobile device

  • @hackeditz2.0
    @hackeditz2.0 3 ปีที่แล้ว +1

    Hii bro all looks osom🤩🤩 but it does not work in android device can you fix it🙄🙄

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      There is no fix bro. Mouse events are not work on mobiles.

    • @hackeditz2.0
      @hackeditz2.0 3 ปีที่แล้ว

      @@CodingNepal so can I use mouse in mobile and use it? Throughout OTG

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

    Did the exact same, but nothing is working even a bit..😵‍💫

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

    hello bro nice work.
    but i want something different.... i will put this wrapper into another div which width will 75% from body... so i want that the wrapper element will not go outside of its parent div
    please tell me the process

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

    Next card slider please

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      Here is the video - th-cam.com/video/YunLfczBbkY/w-d-xo.html

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

    goddess

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

    thanks

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

    You say "Live Demo or Download Codes of this Draggable Div"
    But there is NO ACTUAL place where we can Download source .
    Please provide Download URL .
    Thank you !!!

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

      Just click on Download Code Files button on the demo page and you'll redirected to my website. Search the title of the video and you'll see the blog post with source codes.

  • @AbdurRahman-qc3ip
    @AbdurRahman-qc3ip 3 ปีที่แล้ว +2

    op

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

      Thanks 🔥

    • @AbdurRahman-qc3ip
      @AbdurRahman-qc3ip 3 ปีที่แล้ว +2

      @@CodingNepal thanks to you bro to teach us such a good things

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

      You're welcome bro

  • @grandmaster-yo-yo
    @grandmaster-yo-yo ปีที่แล้ว

    If you're about to make a draggable image, put draggable="false" attribute in the HTML, won't work without it

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

    You are awesome.
    What's Your name?

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

      Thanks and I'm Prakash

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

    great video!! anybody know what exactly `${}` in this example does?

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

      It is called template strings (" ` ` "), it is used to insert variables in strings.

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

    A lot of people watch content on mobile devices ... make the font bigger or at least talk while you write or do both. This is very hard to understand to people like me who has a little impaired eyes, and most people in software field loose eyesight staring for a long time in front of their screens

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

      Also for my front end developers... there seems to be mousemove event listener, which gives you mouse events , which you pair with mouse up and down events the object contains movementX and movementY keys .. which you add to your div after getting its computedwidth

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

    Is Free Fire banned in Nepal ?

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      I don't know about it.

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

    Bro I need English to nepali date converter

    • @CodingNepal
      @CodingNepal  3 ปีที่แล้ว

      Okay I'll think about it

    • @asdfrewqtyukh9989
      @asdfrewqtyukh9989 3 ปีที่แล้ว

      @@CodingNepal thanks bro & if you would keep tutorial videos than it would be better. Like Javascript tutorial for beginners, Css tutorial, jQuery tutorial, etc this will help you & us as well nowadays people try to learn coding & they search for tutorials so if you would keep that then your channel would grow faster than now

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

    First

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

      Great.. Enjoy the video.

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

      @@CodingNepal yeah! OF Cause bro

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

    English to nepali date

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

    English to nepali date

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

    * Thanks BUT
    What I really want to know is "how to Drop an image AMYWHERE om Page"
    Can you help me out with that ? pure js no links to other web stuff ,
    Or can anyone else aim me at a Tutorial that can Help ?
    Thanks