Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
¿Cómo prevenir la función en los elementos de los niños?

Tengo un código para el elemento arrastrable.

 var offsetX; var offsetY; Element.prototype.makeDraggable=function(){ var o=this o.onmousedown=function(e){ offsetX=e.pageX-parseInt(o.style.left) offsetY=e.pageY-parseInt(o.style.top) document.onmousemove=function(e) { o.style.left=Math.min(Math.max(e.pageX-offsetX,o.parentNode.clientWidth-o.clientWidth),0)+'px'; o.style.top=Math.min(Math.max(e.pageY-offsetY,o.parentNode.clientHeight-o.clientHeight),0)+'px'; } document.onmouseup = function(e) { document.onmousemove=o.onmouseup=null } } o.ondragstart = function(){return 0} } document.getElementById('object1').makeDraggable(); let spot = document.querySelectorAll('#grid-holder > div'); for(var i = 0; i < spot.length; i ++) { spot[i].onclick = function(){ inventar(); }; } function inventar() { alert(); }
 <div id="parent"> <div id="object1" style="left: 1px; top: 1px;"> <div class="grid-holder" id="grid-holder"> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> <div></div><div></div><div></div> </div> </div> </div>

Cuando hago clic en #grid-holder> div, tengo un mensaje de alerta, pero ¿cómo evitar esta acción cuando arrastro el elemento #object1 manteniendo el elemento de los niños?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

var offsetX; var offsetY; var moved = false; Element.prototype.makeDraggable = function(ev){ var o = this; o.onmousedown = function(e){ offsetX = e.pageX-parseInt(o.style.left); offsetY = e.pageY-parseInt(o.style.top); moved = false; document.onmousemove = function(e) { o.style.left = Math.min(Math.max(e.pageX-offsetX,o.parentNode.clientWidth-o.clientWidth),0)+'px'; o.style.top = Math.min(Math.max(e.pageY-offsetY,o.parentNode.clientHeight-o.clientHeight),0)+'px'; moved = true; } document.onmouseup = function(e) { document.onmousemove = o.onmouseup = null; } } o.ondragstart = function(){ return 0; } } document.getElementById('object1').makeDraggable(); let spot = document.querySelectorAll('#grid-holder > div'); for(var i = 0; i < spot.length; i ++) { spot[i].onclick = function(){ inventar(); }; } function inventar() { if(!moved) alert(); }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda