Mousedown event handler of an object within a Layer : Mouse Event « Event « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » Event » Mouse Event 
Mousedown event handler of an object within a Layer
  

/*
Examples From
JavaScript: The Definitive Guide, Fourth Edition

Legal matters: these files were created by David Flanagan, and are
Copyright (c) 2001 by David Flanagan.  You may use, study, modify, and
distribute them for any purpose.  Please note that these examples are
provided "as-is" and come with no warranty of any kind.

David Flanagan
*/

<script>
/**
 * This function is intended for use in a mousedown event handler of an object
 * within a Layer.  The first argument must be a Layer object.  The second
 * argument must be the Event object for the mousedown event.
 **/
function beginDrag(layerToDrag, event) {
    // This nested function responds to mousemove events and moves the layer.
    function moveHandler(event) {
  // Move the element to the current mouse position, adjusted as
  // necessary by the offset of the initial mouse click.
  layerToDrag.moveTo(event.pageX - deltaX, event.pageY-deltaY);

  // Don't take any default action, and don't propagate further.
  return false;
    }

    // This nested function handles mouseup events.
    // It stops capturing events, and de-register the handlers.
    function upHandler(event) {
  // Stop capturing and handling drag events
  document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
  document.onmousemove = null;
  document.onmouseup = null;

  // Don't take any default action, and don't propagate further.
  return false;
    }

    // Compute the distance between the upper left of the layer and and the
    // mouse click. The moveHandler function below needs these values.
    var deltaX = event.pageX - layerToDrag.left;
    var deltaY = event.pageY - layerToDrag.top;

    // Arrange to capture mousemove and mouseup events.
    // Then arrange to handle them using the functions defined below.
    document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    document.onmousemove = moveHandler;
    document.onmouseup = upHandler;
}
</script>
<!-- Here's how we might use beginDrag() in Netscape -->
<!-- Define a layer using CSS attributes -->
<div id="div1" style="position:absolute; left:100px; top:100px;">
<!-- Give the layer some content, and a mousedown event handler -->
<img src="images/plus.gif" width="20" height="20"
     onmousedown="if (event.modifiers & Event.SHIFT_MASK)
                      beginDrag(window.document.div1, event);">
</div>


           
         
    
  
Related examples in the same category
1. Catches and manages the mouse's events
2. Mouse and key event (IE)
3. Mouse in image and out
4. Image Mouse on and out
5. Mouse cross hairs
6. Mouse Drag and Drop
7.  Creating a Rollover Effect
8. Codependent Link Tag and the onMouseOver Event
9. Which mouse button was clicked?
10. Which element was clicked
11. Mouse over event
12. Get component From Point (Mouse)
13. Cutting and Pasting under Script Control
14. Using Drag-Related Event Handlers
15.  Using onDragEnter and onDragLeave Event Handlers
16. Using onMouseDown and onMouseUp Event Handlers
17. Dragging Elements with onMouseMove
18. Using the toElement and fromElement Properties
19.  The onBeforeCopy Event Handler
20. Called from an onmousedown event handler
21. Cursor Arrival and Departure
22. Use Mouse over action to transfer url location
23. Get mouse position with on mouse move event (IE)
24. Get mouse position in mouse down event (IE)
25. H1 double click events
26. Return boolean value for on click event
27. Register mouse down event(IE)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.