Ho questo codice
codice:
<script type="text/javascript">
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
//Aggiunta
var imgpath = this.targetobj.src;
var fieldname = imgpath.substring(imgpath.lastIndexOf("/")+1, imgpath.length-4);
document.saveformazione.elements[fieldname+"_x"].value=this.offsetx+evtobj.clientX-this.x;
document.saveformazione.elements[fieldname+"_y"].value=this.offsety+evtobj.clientY-this.y;
//la riga seguente è solo di debug, a script finito si può eliminare.
document.saveformazione.testo.value=fieldname+" X = "+document.saveformazione.elements[fieldname+"_x"].value+" Y = "+document.saveformazione.elements[fieldname+"_y"].value;
//Fine aggiunta
return false
}}}
dragobject.initialize()
</script>
Il quale mi permette di draggare delle immagini ed avere in un campo input text le coordinate sia durante il drag che alla fine del drag...
------------------------------------
Vorrei implementare il passaggio dei dati ad una pagina remota PHP dati quali, nome immagine, coordinate x e coordinate y.
Vorrei poter passare i dati a questa pagina a fine drag di un singolo oggetto, così da potermi salvare la posizione finale nel db.
So che esiste l'oggetto HttpRequest che fa sta cosa, ma non saprei come implementarlo nella funzione sopra postata...
:master: