topical media & game development

talk show tell print

professional-javascript-13-SimulatedDragAndDropExample2.htm / htm

          <title>Simulated Drag And Drop Example</title>
          <script type="text/javascript" src="eventutil.js"></script>
          <script type="text/javascript">
              function handleMouseMove() {
                  var oEvent = EventUtil.getEvent();
                  var oDiv = document.getElementById("div1");
         = oEvent.clientX;
         = oEvent.clientY;
              function handleMouseDown() {
                  EventUtil.addEventHandler(document.body, "mousemove", handleMouseMove);
                  EventUtil.addEventHandler(document.body, "mouseup", handleMouseUp);
              function handleMouseUp() {
                  EventUtil.removeEventHandler(document.body, "mousemove", handleMouseMove);
                  EventUtil.removeEventHandler(document.body, "mouseup", handleMouseUp);
          <style type="text/css">
              #div1 {
                  background-color: red;
                  height: 100px;
                  width: 100px;
                  position: absolute;
          <p>Try dragging the red square.</p>
          <p><div id="div1" onmousedown="handleMouseDown()"></div> </p>

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.