Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Исправьте Drag & Drop (https://javascript.ru/forum/dom-window/25657-ispravte-drag-drop.html)

_Vadik_ 11.02.2012 22:04

Исправьте Drag & Drop
 
Квадрат переносится только по горизонтали
<html>
<head>
<script>
function move(div){
document.onmousedown=function(){return false}
div.style.cursor='move';
document.onmousemove=function(e){
x=e.pageX;
y=e.pageY;
left=div.offsetLeft;
top=div.offsetTop;
left=x-left;
top=y-top;
document.onmousemove=function(e){
x=e.pageX;
y=e.pageY
div.style.top=y-top+'px';
div.style.left=x-left+'px';
}
}
document.onmouseup=function(){
div.style.cursor='auto';
document.onmousedown=function(){}
document.onmousemove=function(){}
}
}
</script>
</head>
<body>
<div style="width:200px; height:200px; background:#ffff00; position:relative;" onMouseDown="move(this)"></div>
</body>
</html>


Часовой пояс GMT +3, время: 03:36.