Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6012713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:26:38+00:00 2026-05-23T02:26:38+00:00

I have a debugger log that I’ve written in JavaScript for a project I’m

  • 0

I have a debugger log that I’ve written in JavaScript for a project I’m working on. The log is basically an <aside> tag in HTML5 that only shows when needed. I wanted to play around with the idea of being able to move the log around the screen, as it may overlap certain things (which is fine for my project). However, I can’t seem to figure out how to use HTML5 to properly drag and drop the tag so that it can be placed anywhere on the screen (well, or within a <div> element).

After reading on HTML5’s drag and drop support, I have a basic understanding of how it works, but I’m not sure where to start when it comes to allowing the div to be placed anywhere (it’s z-index is a high value, so as I said, overlapping is fine).

Any suggestions?

Oh, and I’d like to try and avoid using external libraries for this project, wherever possible. I’m trying to do this in pure JavaScript/HTML5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:26:39+00:00Added an answer on May 23, 2026 at 2:26 am

    Drag and drop doesn’t move elements around, if you want the element to move when you drop it then you have to set the new position of the element in the drop event. I’ve done an example which works in Firefox and Chrome, here are the key points:

    function drag_start(event) {
        var style = window.getComputedStyle(event.target, null);
        event.dataTransfer.setData("text/plain",
        (parseInt(style.getPropertyValue("left"),10) - event.clientX) + ',' + (parseInt(style.getPropertyValue("top"),10) - event.clientY));
    } 
    

    The dragstart event works out the offset of the mouse pointer from the left and top of the element and passes it in the dataTransfer. I’m not worrying about passing the ID because there’s only one draggable element on the page – no links or images – if you have any of that stuff on your page then you’ll have to do a little more work here.

    function drop(event) {
        var offset = event.dataTransfer.getData("text/plain").split(',');
        var dm = document.getElementById('dragme');
        dm.style.left = (event.clientX + parseInt(offset[0],10)) + 'px';
        dm.style.top = (event.clientY + parseInt(offset[1],10)) + 'px';
        event.preventDefault();
        return false;
    }
    

    The drop event unpacks the offsets and uses them to position the element relative to the mouse pointer.

    The dragover event just needs to preventDefault when anything is dragged over. Again, if there is anything else draggable on the page you might need to do something more complex here:

    function drag_over(event) {
        event.preventDefault();
        return false;
    } 
    

    So bind it to the document.body along with the drop event to capture everything:

    var dm = document.getElementById('dragme');
    dm.addEventListener('dragstart',drag_start,false);
    document.body.addEventListener('dragover',drag_over,false);
    document.body.addEventListener('drop',drop,false); 
    

    If you want this to work in IE you’ll need to convert the aside to an a element, and, of course, all the event binding code will be different. The drag and drop API doesn’t work in Opera, or on any mobile browsers as far as I’m aware. Also, I know you said you don’t want to use jQuery, but cross browser event binding and manipulating element positions are the sort of things that jQuery makes much easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Panel that I'm setting visible=true explicitly. The debugger passes over that
What debugging tools are available for directshow filters? Presently, I have a project that
I have a manifest.json file that looks like this: { name: Zend Debugger Extension,
I have a Windows service written in C# that spawns several worker threads. Those
I have a strange bug that appears to happen only when the program isn't
I have a website that i've been working on for about a year now.
I have a pretty large project that just recently started crashing on exit. I
I have one debugger visualizer for seeing list of class object in the form
I have Microsoft Script debugger installed and selected (somwhere) as the script debugger of
I have created a debugger visualizer in VS2008. There are two classes i've made,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.