Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
javascript drag and drop - double drag with two clicks

I am working with drag and drop and so far it works fine. I have pictures, which I can position in my different drop areas. To keep the original pictures, I drag a clone. Clicking (mousedown) on the picture and drag it, everything works fine. I have a clone of the picture in my desired drop area.

My problem: Clicking on the picture more than once BEFORE dragging it, the dragevents accumalate. How can I prevent this? Removing the eventlistener with "mouseup" does not work...

Happy for some help. Here is my basic code:

let myPictures = document.querySelectorAll('.myPictures');

myPictures.forEach(function(myPic) {
    myPic.addEventListener('mousedown', evLiMyPic);
    function evLiMyPic(e){
      if(!resize){
        mousedownMyPic(e, myPic);
      }  
    }


    myPic.addEventListener('mouseup', evLiMyPicMouseUp);
    function evLiMyPicMouseUp(e){
      if(!isResizing){
        mouseupMyPic(e, myPic);
      }  
    }
});

function mousedownMyPic(e, myPic){
  
    myPic.addEventListener('dragstart', dragstartMyPic);
    myPic.addEventListener('dragend', dragendMyPic);

    let dropAreas = document.querySelectorAll('.dropAreaDrag');

    dropAreas.forEach(function(dropArea) {
        dropArea.addEventListener('dragover', evLidragoverMyPic);
        function evLidragoverMyPic(e){
        dragoverMyPic(e, dropArea);
        }
        dropArea.addEventListener('drop', evLidropMyPic);
        function evLidropMyPic(e){
        dropMyPic(e, dropArea);
        }
    });
}

function mouseupMyPic(e, myPic){
  
    myPic.removeEventListener('dragstart', dragstartMyPic);
    myPic.removeEventListener('dragend', dragendMyPic);

    let dropAreas = document.querySelectorAll('.dropAreaDrag');

    dropAreas.forEach(function(dropArea) {
        dropArea.removeEventListener('dragover', evLidragoverMyPic);
        function evLidragoverMyPic(e){
        dragoverMyPic(e, dropArea);
        }
        dropArea.removeEventListener('drop', evLidropMyPic);
        function evLidropMyPic(e){
        dropMyPic(e, dropArea);
        }
    });
}


function dragstartMyPic(e){
    // do something
}

function dragendMyPic(e){
    // do something
}

function dragoverMyPic(e){
    // do something
}

function dropMyPic(e){
    // do something
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!