Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda