ciao a tutti,
sto cercando di creare una routine che mi permette di spostare un div, tramite il mouse, appunto il drag & drop.
ecco quello che sono riuscito a fare, prendendo spunto qua e la:
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
<head>
<title> prova</title>
<style>
#cont{
width:300px;
}
#cont{
position: relative;
top:0px;
left:0px;
}
.bordo{
position:relative;
float:left;
background-color: black;
}
</style>
</head>
<body>
<script type="text/javascript">
<!--
var giu = true;
var L, T, X, Y;
function coordinate(coord){
giu = true;
L = document.getElementById("cont").style.left;
T = document.getElementById("cont").style.top;
X=coord.pageX;
Y=coord.pageY;
document.onmousemove = muovi;
}
function muovi(){
var x, y;
if (giu){
y= T + coord.pageY - Y;
document.getElementById("cont").style.top = y + "px";
x= L + coord.pageX - X;
document.getElementById("cont").style.left = x + "px";
}
}
function su(){
giu = false;
}
document.getElementById("top").onmousedown=coordinate;
document.getElementById("bottom").onmouseup=su;
//-->
</script>
<div id="cont">
<div style="width:3px; height: 3px; cursor:nw-resize" class="bordo"></div>
<div style="width:294px; height: 3px; cursor:n-resize" class="bordo"></div>
<div style="width:3px; height: 3px; cursor:ne-resize" class="bordo"></div>
<div style="width:3px; height: 175px; cursor:w-resize" class="bordo"></div>
<div style="width:294px; float:left">
<div id="top" style="height:25px; background-color: blue; cursor:move;" ></div>
<div id="bottom" style="height:150px; background-color: yellow;"></div>
</div>
<div style="width:3px; height: 175px; cursor:e-resize" class="bordo"></div>
<div style="width:3px; height: 3px; cursor:sw-resize" class="bordo"></div>
<div style="width:294px; height: 3px; cursor:s-resize" class="bordo"></div>
<div style="width:3px; height: 3px; cursor:se-resize" class="bordo"></div>
</div>
</body>
</html>
per adesso mi basta la compatibilità con firefox.
grazie