Ciao, anche io sto facendo la stessa cosa. Sto cercando di sfruttare il DOM per simulare il drag e drop del mouse. Ho scritto questo codice, che funziona ma non riesco a limitare l'area di trascinamento del mouse, cioè una volta selezionato l'oggetto vorrei che l'oggetto si potesse trascinare solo nel <div> che dico io. Vi posto il codice:
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript DOM Drag & Drop</title>
<style><!--
.dragclass {
position:absolute;
top:0;
left:0;
width:12.5em;
cursor : move;
border:1px solid #ff00ff;
background-color:#ffeedd;
color:#000000;
}
#container {
position:absolute;
top:30px;
left:30px;
width:25em;
height:25em;
border:1px solid #000000;
}
--></style>
<script type="text/javascript"><!--
if (document.getElementById){
var container,maxX,maxY;
var n = 0;
var dragok = false;
var y,x,d,dy,dx;
function move(e) {
if (!e) e = window.event;
if (dragok){
d.style.left = dx + e.clientX - x + "px";
d.style.top = dy + e.clientY - y + "px";
return false;
}
}
function down(e) {
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.className == "dragclass"){
container = document.getElementById("container");
dragok = true;
temp.style.zIndex = n++;
d = temp;
dx = parseInt(temp.style.left+0);
dy = parseInt(temp.style.top+0);
x = e.clientX;
y = e.clientY;
maxX=container.offsetLeft + container.offsetWidth;
maxY=container.offsetTop + container.offsetHeight;
document.onmousemove = move;
return false;
}
}
function up(){
dragok = false;
document.onmousemove = null;
}
document.onmousedown = down;
document.onmouseup = up;
}
//End.
//--></script>
</head>
<body>
<div id="container">
<div class="dragclass">
[url="http://www.3anniepoi.it/"]Hello World![/url]
</div>
</div>
</body>
</html>
Vorrei un suggerimento.
Grazie
Noot