1 / 4

Draggable Rectangle

Draggable Rectangle. <style type="text/css"> #div1 { position: absolute; } </style> ... <div id="div1" onmousedown="mouseDown(event);" onmousemove="mouseMove(event);" onmouseup="mouseUp(event);">Drag Me!</div>. Event Handlers. isMouseDown = false;

lhorner
Download Presentation

Draggable Rectangle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Draggable Rectangle <style type="text/css"> #div1 { position: absolute; } </style> ... <div id="div1" onmousedown="mouseDown(event);" onmousemove="mouseMove(event);" onmouseup="mouseUp(event);">Drag Me!</div> CS 142 Lecture Notes: Forms

  2. Event Handlers isMouseDown = false; function mouseDown(event) { mouseX = event.clientX; mouseY = event.clientY; isMouseDown = true; } function mouseMove(event) { if (!isMouseDown) { return; } element = document.getElementById("div1"); element.style.left = (element.offsetLeft + (event.clientX - mouseX)) + "px"; element.style.top = (element.offsetTop + (event.clientY - mouseY)) + "px"; mouseX = event.clientX; mouseY = event.clientY; } function mouseUp(event) { isMouseDown = false; } CS 142 Lecture Notes: Forms

  3. Which Element Gets Event? <body> <table> <tr> <td>xyz</td> </tr> </table> </body> Click on this CS 142 Lecture Notes: Forms

  4. CS 142 Lecture Notes: Forms

More Related