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

242
Visualizações
How to have a button that adds draggables from Draggabilly?

I am working on a website which uses desandro's package Draggabilly. I am wondering how I can implement a button which will add a new working draggable. My current method (shown below) creates the draggable but does not allow it to drag.

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Testing creating a button to add a draggable</title>
        <meta charset="UTF-8">
        <meta name="viewpoint" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="styles.css">
    </head>

    <body>
        <button id="addDragBtn">Add draggable</button>

        <script src="scripts.js"></script>
    </body>
</html>

CSS

body { 
    font-family: sans-serif; 
}

.draggable {
    width: 140px;
    height: 140px;
    background: #F90;
    border-radius: 10px;
    cursor: move;
}

.draggable.is-pointer-down {
    background: #09F;
}

.draggable.is-dragging { 
    opacity: 0.7; 
}

Javascript

let $draggable = $('.draggable').draggabilly();

function addDrag() {
    var div = document.createElement('div');

    div.className = "draggable";

    document.body.appendChild(div);
};

let btn = document.getElementById("addDragBtn");
addDragBtn.addEventListener(
    'click', event => {
        addDrag();  
    }
);
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