Drag and Drop!

This function of DHTML is only for IE4. Well NC 4 has this function but too hard to figure out(?). OK, I am working on DHTML Nascape Communicator section. You know why? They(Netscape) turn to free! I like free stuff but I still like IE better than NC4. However, Here is the code;


  move = 0;
  drag = 0;

  function init() {
	window.document.onmousemove = mmove;
	window.document.onmousedown = down;
	window.document.onmouseup = up;
	window.document.ondragstart = start;
  }

  function down() { 
	if (drag) {
		xleft = window.event.x - parseInt(block.style.left)
		xtop = window.event.y - parseInt(block.style.top)
		block.style.zIndex += 3
		move = 1
	}
  }

  function mmove() {
	if (move) {
		block.style.left = window.event.x - xleft
		block.style.top = window.event.y - xtop
	}
  }

  function start() {
	window.event.returnValue = false
  }

  function up() {
	move = 0
  }
  

Yahoo! It is hard to explain, just make it yours and practice! You need to put special codes in div tag. Here is that code;


  onmouseover="block = DivID; drag = 1;"
  onmouseout="drag = 0"
  

Here is the example.

Go back to home.