Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: для новичков > Как сделать залипание в drag&drop ?


Автор: Sectoid 5.3.2010, 21:56
<HTML>
<HEAD>
<TITLE></TITLE>
<script LANGUAGE="JavaScript">
<!--
var Block=new Array(0,0,0,0,0);
//Конец переменных
//document.all.text1.value=Block[2];
//document.all.text2.value=Block[3];
//document.all.text3.value=document.all.img0.width;
//if((Block[0]>)||(Block[0]<Block[0])){document.all.text3.value='Есть !'};
//-->
function MoveObject()
{
if(window.dragObj)
  {
  window.dragObj.style.left=event.x-window.dx;
  window.dragObj.style.top=event.y-window.dy;
  Block[0]=window.dragObj.style.left;
  Block[1]=window.dragObj.style.top;
  Block[2]=document.all.img0.style.left;
  Block[3]=document.all.img0.style.top;
  document.all.text1.value=Block[0];
  document.all.text2.value=Block[1];
  document.all.text3.value=Block[2];
  document.all.text4.value=Block[3];
//почему-то следующее условие не работает ...
  if((Block[0]>Block[2])&&(Block[0]<Block[2]+50)){Block[4]=1;document.all.text5.value='Есть !'}
  }
}
</SCRIPT>
<BODY
onmouseup="window.dragObj=null"
onmousemove="MoveObject()">

<INPUT type="text" name="text1" STYLE="position: absolute; left=5; top=5;">
<INPUT type="text" name="text2" STYLE="position: absolute; left=5; top=30;">
<INPUT type="text" name="text3" STYLE="position: absolute; left=5; top=55;">
<INPUT type="text" name="text4" STYLE="position: absolute; left=5; top=80;">
<INPUT type="text" name="text5" STYLE="position: absolute; left=5; top=105;">
<IMG name="img0" STYLE="position: absolute; cursor: hand; Left=400; Top=250" 
src='Images/Empty1.bmp' title='Пусто1'>
<IMG name="img1" STYLE="position: absolute; cursor: hand; Left=100; Top=200" 
src='Images/Block1.bmp' title='Блок1' onmousedown="window.dragObj=this;
window.dx=event.x-this.offsetLeft;
window.dy=event.y-this.offsetTop" ondragstart="return false">
<IMG name="img2" STYLE="position: absolute; cursor: hand; Left=300; Top=200" 
src='Images/Block2.bmp' title='Блок2' onmousedown="window.dragObj=this;
window.dx=event.x-this.offsetLeft;
window.dy=event.y-this.offsetTop" ondragstart="return false">
<IMG name="img3" STYLE="position: absolute; cursor: hand; Left=150; Top=300" 
src='Images/Block3.bmp' title='Блок3' onmousedown="window.dragObj=this;
window.dx=event.x-this.offsetLeft;
window.dy=event.y-this.offsetTop" ondragstart="return false">
</BODY>
</HTML>

Автор: 12345c 5.3.2010, 23:03
1. Оформите код в теги [code].
2. Это вопрос или ответ?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)