<html>
<head>
<script>
var startPositionX = null;
var startPositionY = null;
var intervalX = 0;
var intervalY = 0;
var globalElem = null;
function getElemShadow(elemId, prototypeId) {
elem = document.getElementById(elemId);
prototype = document.getElementById(prototypeId);
if (elem && prototype) {
globalElem = elem;
elem.style.visibility = "visible";
/*elem.style.borderColor = "black";
elem.style.borderWidth = "1px";
elem.style.borderStyle = "dashed";*/
startPositionY = elem.style.top;
startPositionX = elem.style.left;
document.body.attachEvent('onmouseup', setElemShadow);
document.body.attachEvent('onmousemove', moveElemShadow);
if (window.event.clientX || window.event.clientY) {
intervalX = window.event.clientX - elem.offsetLeft;
intervalY = window.event.clientY - elem.offsetTop;
}
}
}
function moveElemShadow() {
if (globalElem && (globalElem != null)) {
mX = document.getElementById("mouseX");
mY = document.getElementById("mouseY");
iX = document.getElementById("imageX");
iY = document.getElementById("imageY");
if (window.event.clientX || window.event.clientY) {
iX.value = elem.style.left;
iY.value = elem.style.top;
mX.value = window.event.clientX;
mY.value = window.event.clientY;
globalElem.style.left = window.event.clientX - intervalX;
globalElem.style.top = window.event.clientY - intervalY;
}
}
}
function setElemShadow() {
if (globalElem && (globalElem != null)) {
globalElem.style.top = startPositionY;
globalElem.style.left = startPositionX;
globalElem.style.visibility = "hidden";
globalElem = null;
document.body.attachEvent('onmouseup', null);
document.body.attachEvent('onmousemove', null);
}
}
function aaa(e) {
alert("Ура, работает!");
}
</script>
</head>
<body>
<table border="1" bordercolor="black" cellpadding="4" cellspacing="0">
<tr>
<td colspan="3" align="center">
Перемещение объектов.
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<table onmousemove="moveElemShadow(this)" onmouseup="setElemShadow(this)" id="table1" style="visibility: hidden; z-index: 1; position: absolute; width: 100px; height: 30px; border-color: black; border-width: 1px; border-style: dashed;">
<tr>
<td>
</td>
</tr>
</table>
<input type="button" style="width: 100px; height: 30px; z-index: -2;" value="Фишка 1" id="fishka1" onmousedown="getElemShadow('table1', 'fishka1')">
</td>
</tr>
<tr>
<td>
</td>
<td>
<table onmousemove="moveElemShadow(this)" onmouseup="setElemShadow(this)" id="table2" style="visibility: hidden; z-index: -1; position: absolute; width: 100px; height: 30px; border-color: black; border-width: 1px; border-style: dashed;">
<tr>
<td>
</td>
</tr>
</table>
<input type="button" style="width: 100px; height: 30px; z-index: -2;" value="Фишка 2" id="fishka2" onmousedown="getElemShadow('table2', 'fishka2')">
</td>
<td onmouseup="aaa(this)" style="z-index: 0; height: 200px; width: 200px;">
Наведи элемент сюда и отпусти.
</td>
</tr>
<tr>
<td>
<table onmousemove="moveElemShadow(this)" onmouseup="setElemShadow(this)" id="table3" style="visibility: hidden; z-index: 0; position: absolute; width: 100px; height: 30px; border-color: black; border-width: 1px; border-style: dashed;">
<tr>
<td>
</td>
</tr>
</table>
<input type="button" style="width: 100px; height: 30px; z-index: -2;" value="Фишка 3" id="fishka3" onmousedown="getElemShadow('table3', 'fishka3')">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<br>
Курсор мышки X
<input type="text" name="mouseX" id="mouseX">
<br>
Курсор мышки Y
<input type="text" name="mouseY" id="mouseY">
<br>
Координата картинки X
<input type="text" name="imageX" id="imageX">
<br>
Координата картинки Y
<input type="text" name="imageY" id="imageY">
</body>
</html>