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

162
Views
Deshabilitar arrastrar en la página web HTML

Estoy tratando de hacer un boceto de grabado con HTML donde tengo un contenedor div con muchos elementos div, usando la visualización de cuadrícula en CSS.

HTML: <div id="canvas"></div>

Luego uso JS para agregar los elementos div:

 for(let i =1;i<=256;i++){ let squareDiv = document.createElement("div"); canvasElement.appendChild(squareDiv); canvasElement.setAttribute("draggable","false");}

El atributo arrastrable no funciona.

Cuando hago clic y arrastro para dibujar algo, está arrastrando una imagen tenue como se muestra a continuación: ingrese la descripción de la imagen aquí

¿Hay algún atributo que pueda usar para deshabilitar esto?

Editar: Todo el código javascript:

 canvasElement =document.getElementById("canvas") let isToggling = false; function enableToggle(e) { isToggling = true; } function disableToggle() { isToggling = false; } function toggle(e) { if (isToggling === false) { return; } console.log('toggle:', e.target); e.target.classList.add('red'); } for(let i =1;i<=256;i++){ let squareDiv = document.createElement("div"); canvasElement.appendChild(squareDiv); canvasElement.setAttribute("draggable","false"); squareDiv.onmousedown=enableToggle; squareDiv.onmouseenter=toggle; squareDiv.onmouseup=disableToggle; }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar e.preventDefault() para evitar que ocurra el efecto predeterminado dentro de su evento onmousedown.

Agregue e.preventDefault() dentro de su función enableToggle(e)

 function enableToggle(e) { isToggling = true; e.preventDefault() }

Si eso no funciona, agréguelo a alternar () y deshabilite Alternar ()

about 4 years ago · Santiago Trujillo Report
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!