This topic has not yet been rated - Rate this topic

componentFromPoint method

[This documentation is preliminary and is subject to change.]

Returns the component located at the specified coordinates via certain events.

Syntax

object.componentFromPoint(x, y)

Standards information

There are no standards that apply here.

Parameters

x [in]

Type: long

 Specifies the client window coordinate of x.

y [in]

Type: long

 Specifies the client window coordinate of y.

Return value

Type: StringString. Returns one of the following possible values.
Return valueDescription
empty string

Component is inside the client area of the object.

outside

Component is outside the bounds of the object.

scrollbarDown

Down scroll arrow is at the specified location.

scrollbarHThumb

Horizontal scroll thumb or box is at the specified location.

scrollbarLeft

Left scroll arrow is at the specified location.

scrollbarPageDown

Page-down scroll bar shaft is at the specified location.

scrollbarPageLeft

Page-left scroll bar shaft is at the specified location.

scrollbarPageRight

Page-right scroll bar shaft is at the specified location.

scrollbarPageUp

Page-up scroll bar shaft is at the specified location.

scrollbarRight

Right scroll arrow is at the specified location.

scrollbarUp

Up scroll arrow is at the specified location.

scrollbarVThumb

Vertical scroll thumb or box is at the specified location.

handleBottom

Bottom sizing handle is at the specified location.

handleBottomLeft

Lower-left sizing handle is at the specified location.

handleBottomRight

Lower-right sizing handle is at the specified location.

handleLeft

Left sizing handle is at the specified location.

handleRight

Right sizing handle is at the specified location.

handleTop

Top sizing handle is at the specified location.

handleTopLeft

Upper-left sizing handle is at the specified location.

handleTopRight

Upper-right sizing handle is at the specified location.

 

Remarks

The componentFromPoint method, available as of Microsoft Internet Explorer 5, is applicable to any object that can be given scroll bars through Cascading Style Sheets (CSS).

The componentFromPoint method might not return the same object consistently when it is used with the onmouseover event. Because a user's mouse speed and entry point can vary, different components of an element can fire the onmouseover event. For example, when a user moves the cursor over a textArea object with scroll bars, the event might fire when the mouse enters the component border, the scroll bars, or the client region. After the event fires, the expected element might not be returned, unless the scroll bars were the point of entry for the mouse. In this case, the onmousemove event can be used to provide more consistent results.

For the object's sizing handles to appear, designMode must be On, and the object must be selected.

Examples

This example uses the componentFromPoint method to determine which object the mouse pointer is hovering over.

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


<HTML>
<HEAD>
<SCRIPT>
/*When this function is activated, an alert pops up displays the component at the position of the pointer. */
function ComponentSnapShot(){
   var sElem = "";
   sElem = document.body.componentFromPoint(
      event.clientX,
      event.clientY
   );
   if (sElem=="")
    alert("No component there!");
   else
    alert("Component: " + sElem);    
}
function trackElement(){
   var sElem = "";
   sElem = document.body.componentFromPoint(
      event.clientX,
      event.clientY
   );
   window.status = "mousemove " + event.clientX + ", "
      + event.clientY +
      " The mouse pointer is hovering over: " + sElem;
   
}
</SCRIPT>
</HEAD>
<!-- There are several different events that can be used with componentFromPoint. Below are a few of them. 
Be carefull! Not all mouse events can be used with componentFromPoint.  -->
<BODY onmousemove="trackElement()" onmousedown="ComponentSnapShot()" onkeydown="ComponentSnapShot()" oncontextmenu="ComponentSnapShot()">
<TEXTAREA COLS=500 ROWS=500>
This text forces scroll bars to appear in the window.
</TEXTAREA>
</BODY>
</HTML>


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
doScroll
onscroll

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Component:outside?
Hey guys,
            I'm using the script as shown but the alert reports "Component: outside" . I'm using it with onscroll like so.
[script]
function ComponentSnapShot(){
var sElem=' ';
sElem = document.getElementById('f1').componentFromPoint(event.clientX, event.clientY);
if(sElem=='scrollbarUP')//No alert ?
alert("HELLO WORLD!");
else
alert("Component: " + sElem);   
}
 addEvent(f1,'scroll',function(){ComponentSnapShot();},false);
[/script]
Click up or down arrows on scroll bar to scroll 100% of div client height?
Yes, I've been looking to get my div to scroll 100% of it's height (the div clientheight) in aether direction so I'd like to see an example with onclick of the up arrow of the scrollbar and the down arrow doing it in the opposite direction. I know this isn't cross browser yet and that touch screen technology is using similar x y coordinate tracking. I'd also like to see a tool tip pop up when the mouse entered the scroll bar area like title="Click Up arrow to go to previous item or Down arrow to go to next item." Probably set on the thumbV mouseover? The div has multiple divs class named itemrow that contain 3 child dives each but itemrow divs span both height and width of the scrollable container div so the nextSibling or previousSibling of itemrow might be usable with div.onscroll scrollIntoView but I haven't been able to get that to work either. Any direction would be greatly appreciated. Best regards, Heinz Stapff.