setCapture method

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
10 out of 15 rated this helpful - Rate this topic

Sets the mouse capture to the object that belongs to the current document.

Syntax

object.setCapture(containerCapture)

Parameters

containerCapture [in, optional]

Type: Boolean

Specifies one of the following values.

true (true)

Default. Events originating in a container are captured by the container.

false (false)

Events originating in a container are not captured by the container.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

There are no standards that apply here.

Remarks

After mouse capture is set to an object, all mouse events for the document are routed to that object. Supported mouse events include onmousedown, onmouseup, onmousemove, onclick, ondblclick, onmouseover, and onmouseout. The srcElement property of the window event object always returns the object that is positioned under the mouse, instead of the object that has mouse capture.

Mouse clicks automatically trigger the onlosecapture event. To retain mouse capture, call setCapture inside the onclick event handler.

When the containerCapture parameter is set to true, a container object, such as a div, captures mouse events for all objects in it. By passing the value false, objects in that container can fire events, and cancel event bubbling.

Drag-and-drop operations, such as the ondragstart event, and text selection through the user interface are disabled when mouse capture is set programmatically. The following key events are unaffected by mouse capture and fire as usual: onkeydown, onkeyup, and onkeypress.

Mouse clicks automatically trigger the onlosecapture event. To retain mouse capture, call setCapture inside the onclick event handler. Mouse capture is also lost if the browser window loses focus for any reason (including alerts or pop-up windows).

Note   The containerCapture parameter is available only in Microsoft Internet Explorer 5.5 or later. For earlier versions, do not specify a parameter.

Examples

This example shows how to use mouse capture to animate graphics.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/eyeballEX.htm


<HEAD>
<SCRIPT>
var iRad = 25;
var iX01 = 165;
var iY01 = 170;
var iX02 = 285;
var iY02 = 170;
/* The doImgMouseMove function contains calculations to 
    reposition black.bmp in response to mouse movement  */
   
function doImgMouseMove()
{
  var iX1 = event.x - iX01;
  var iY1 = event.y - iY01;
  var iX2 = event.x - iX02;
  var iY2 = event.y - iY02;
  var change1 = Math.sqrt(iX1 * iX1 + iY1 * iY1);
  var change2 = Math.sqrt(iX2 * iX2 + iY2 * iY2);
  oPupilLeft.style.left = iX01 + iRad * iX1 / change1;
  oPupilLeft.style.top = iY01 + iRad * iY1 / change1;
  oPupilRight.style.left = iX02 + iRad * iX2 / change2;
  oPupilRight.style.top = iY02 + iRad * iY2 / change2;
}
</SCRIPT>
</HEAD>
<BODY onload="oEye.setCapture(false)" 
    onclick="oEye.releaseCapture()"
    ondragstart="event.returnValue = false;">
<INPUT TYPE=button ID=oToggle VALUE="Switch Mouse Capture On" 
    onclick="doClick()">
<IMG ID=oEye SRC="/workshop/graphics/eye.png" 
    onmousemove="doImgMouseMove()">
<IMG ID=oPupilLeft SRC="/workshop/graphics/black.png">
<IMG ID=oPupilRight SRC="/workshop/graphics/black.png">
<P>The eyeballs track pointer movement. When mouse 
    capture is on, they follow the pointer no matter where it 
    is positioned in the document. When mouse capture is off, they 
    detect and follow mouse position only while the pointer is 
    positioned over the eyeball graphic.</P>
<P>In this example, mouse capture is set when the document is 
    loaded. Click anywhere on the document to remove mouse 
    capture.</P>
</BODY>

See also

a
abbr
acronym
address
applet
area
article
aside
b
base
baseFont
bgSound
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
comment
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
figcaption
figure
font
footer
form
frame
frameSet
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=file
input type=hidden
input type=image
input type=password
input type=radio
input type=reset
input type=submit
input type=text
ins
isIndex
kbd
label
legend
li
link
listing
map
mark
marquee
menu
nav
nextID
noBR
noFrames
noScript
object
ol
option
p
plainText
pre
q
rt
ruby
s
samp
script
section
select
small
span
strike
strong
style
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
tt
u
ul
var
wbr
xml
xmp
Reference
onlosecapture
releaseCapture
msSetPointerCapture
msReleasePointerCapture
Conceptual
About Mouse Capture

 

 

Send comments about this topic to Microsoft

Build date: 1/23/2013

Did you find this helpful?
(1500 characters remaining)

Community Additions

© 2013 Microsoft. All rights reserved.