EgEm
11-26-2010, 05:18 PM
Hi good day.
i got a drag and drop script:
<script type="text/javascript">
//Si el navegador del cliente es Mozilla la variable siguiente valdrá true
var moz = document.getElementById && !document.all;
//Flag que indica si estamos o no en proceso de arrastrar el ratón
var estoyArrastrando = false;
//Variable para almacenar un puntero al objeto que estamos moviendo
var dobj;
function arrastrarRaton(e){
if (estoyArrastrando) {
newLeft = moz ? e.clientX : event.clientX;
newTop = moz ? e.clientY : event.clientY;
dobj.style.left = newLeft - parseInt(dobj.style.width)/2;
dobj.style.top = newTop - parseInt(dobj.style.height)/2;
return false;
}
}
function soltarBoton(e) {
onClick = null;
arrastrando = true;
estoyArrastrando = false;
setTimeout("desbloquea()",250);
}
function presionarBoton(e) {
//Obtenemos el elemento sobre el que se ha presionado el botón del ratón
var fobj = moz ? e.target : event.srcElement;
// Buscamos el primer elemento en la que esté contenido aquel sobre el que se ha pulsado
// que pertenezca a la clase objMovible.
while (fobj.tagName.toLowerCase() != "html" && fobj.className != "objMovible") {
fobj = moz ? fobj.parentNode : fobj.parentElement;
}
// Si hemos obtenido un objeto movible...
if (fobj.className == "objMovible") {
// Activamos el flag para indicar que se empieza a arrastrar
estoyArrastrando = true;
// Guardamos un puntero al objeto que se está moviendo en la variable global
dobj = fobj;
// Devolvemos false para no realizar ninguna acción posterior
return false;
}
}
document.onmousedown = presionarBoton;
document.onmouseup = soltarBoton;
document.onmousemove = arrastrarRaton;
document.oncontextmenu=new Function("return false");
</script>
and it works Just fine. i can drag and drop any object i set with the class "Objmovible". but the problem comes when i try to drag and drop an object with a link.
When i try to do that, when i drop the object, i get redirected to the link of the object. so, what im looking for is for a way to, when i start dragging an object, disable the link, but when i drop the object, enable again so, when someone just clicks the object, it gets redirected to the link itself....
Hope i could do it myself but im just starting to learn javascript -__-, and i really need this code working soon as possible...
by the way, im trying to use that code on the index site of www.raulreyesfotografo.com hope that helps...
Thank you.
i got a drag and drop script:
<script type="text/javascript">
//Si el navegador del cliente es Mozilla la variable siguiente valdrá true
var moz = document.getElementById && !document.all;
//Flag que indica si estamos o no en proceso de arrastrar el ratón
var estoyArrastrando = false;
//Variable para almacenar un puntero al objeto que estamos moviendo
var dobj;
function arrastrarRaton(e){
if (estoyArrastrando) {
newLeft = moz ? e.clientX : event.clientX;
newTop = moz ? e.clientY : event.clientY;
dobj.style.left = newLeft - parseInt(dobj.style.width)/2;
dobj.style.top = newTop - parseInt(dobj.style.height)/2;
return false;
}
}
function soltarBoton(e) {
onClick = null;
arrastrando = true;
estoyArrastrando = false;
setTimeout("desbloquea()",250);
}
function presionarBoton(e) {
//Obtenemos el elemento sobre el que se ha presionado el botón del ratón
var fobj = moz ? e.target : event.srcElement;
// Buscamos el primer elemento en la que esté contenido aquel sobre el que se ha pulsado
// que pertenezca a la clase objMovible.
while (fobj.tagName.toLowerCase() != "html" && fobj.className != "objMovible") {
fobj = moz ? fobj.parentNode : fobj.parentElement;
}
// Si hemos obtenido un objeto movible...
if (fobj.className == "objMovible") {
// Activamos el flag para indicar que se empieza a arrastrar
estoyArrastrando = true;
// Guardamos un puntero al objeto que se está moviendo en la variable global
dobj = fobj;
// Devolvemos false para no realizar ninguna acción posterior
return false;
}
}
document.onmousedown = presionarBoton;
document.onmouseup = soltarBoton;
document.onmousemove = arrastrarRaton;
document.oncontextmenu=new Function("return false");
</script>
and it works Just fine. i can drag and drop any object i set with the class "Objmovible". but the problem comes when i try to drag and drop an object with a link.
When i try to do that, when i drop the object, i get redirected to the link of the object. so, what im looking for is for a way to, when i start dragging an object, disable the link, but when i drop the object, enable again so, when someone just clicks the object, it gets redirected to the link itself....
Hope i could do it myself but im just starting to learn javascript -__-, and i really need this code working soon as possible...
by the way, im trying to use that code on the index site of www.raulreyesfotografo.com hope that helps...
Thank you.