473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Finding all elements on specific coordinates

Two problems regarding coordinates:

a) When I click in the screen then I can easyly find the element on the
current corrdinates. But is there a way to find the elements which are
behind the fist on the z-axis?

b) Is there a fast way to find all elements which are within specific
coordinates like 100,100 and 200,200? Currently I walk through the whole
tree and calculate the absolute positions of each elements. It works but
it's really slow.

RK

Jul 20 '05 #1
2 8627
Yep
y-*******@em-lyon.com (Yep) wrote in message news:<d2**************************@posting.google. com>...
Rainer Kugeland <rk*******@t-online.de> wrote in message news:<bf*************@news.t-online.com>...
b) Is there a fast way to find all elements which are within specific
coordinates like 100,100 and 200,200? Currently I walk through the whole
tree and calculate the absolute positions of each elements. It works but
it's really slow.


Not really surprising, if you want to increase speed (apart from
regular code optimization such as reference keeping) I'm afraid you'll
have to change the structure, be it HTML-side with the DOM tree
(nesting HTML elements, therefore taking advantage of events bubbling)
or javascript-side with some kind of naming conventions (IDs) and
maybe related navigation rules. It all depends on _what_ you're trying
to achieve...


Actually in IE only you could also give a look at the elementFromPoint
method, maybe using something near the following (slightly tested
only):
<style type="text/css">
div{position:absolute;left:10px;top:10px;width:100 px;height:100px;}
</style>

<div id="d1" style="background:#f00;z-index:10">Hello</div>
<div id="d2" style="background:#0f0;z-index:20">Hello</div>
<div id="d3" style="background:#00f;z-index:30">Hello</div>

<script type="text/javascript">
document.onclick=function(evt){
var e=window.event, d=document;
if(e && d.elementFromPoint){
var n=e.srcElement, el=n, elems=[];
do {
elems.push(el);
el.style.zIndex = (el.style.zIndex||0)-1000;
el=d.elementFromPoint(e.x, e.y);
} while(el!=n);
elems.toString=function(){
var buf=[];
for(var ii=0; ii<this.length; ii++)
buf.push(this[ii].id);
return buf.join(", ");
}
alert(elems);
for(var ii=0; ii<elems.length; ii++)
elems[ii].style.zIndex = +elems[ii].style.zIndex + 1000;
}
}
</script>
Jul 20 '05 #2
Yep,

thanks for the example. I'll play around with it a bit.
I also think about skipping leafes when the parent leaf is already out
of bounds. But I'm still unsure because in this case I'll loose all
layers which are positioned absolutely...

RK
Actually in IE only you could also give a look at the elementFromPoint
method, maybe using something near the following (slightly tested
only):
<style type="text/css">
div{position:absolute;left:10px;top:10px;width:100 px;height:100px;}
</style>

<div id="d1" style="background:#f00;z-index:10">Hello</div>
<div id="d2" style="background:#0f0;z-index:20">Hello</div>
<div id="d3" style="background:#00f;z-index:30">Hello</div>

<script type="text/javascript">
document.onclick=function(evt){
var e=window.event, d=document;
if(e && d.elementFromPoint){
var n=e.srcElement, el=n, elems=[];
do {
elems.push(el);
el.style.zIndex = (el.style.zIndex||0)-1000;
el=d.elementFromPoint(e.x, e.y);
} while(el!=n);
elems.toString=function(){
var buf=[];
for(var ii=0; ii<this.length; ii++)
buf.push(this[ii].id);
return buf.join(", ");
}
alert(elems);
for(var ii=0; ii<elems.length; ii++)
elems[ii].style.zIndex = +elems[ii].style.zIndex + 1000;
}
}
</script>


Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Victor Engmark | last post by:
When looking for a method to fetch unique elements and counting the number of occurences of each of them, I found quite a lot of gross examples of complex XSL. But after realizing the subtle...
2
by: Pallavi | last post by:
Hello, Suppose I want to highlight a piece of text. I get the x & y co-ordinates on the screen. And using dhtml I am able to highlight the text. Then I try on another machine with different...
3
by: aam | last post by:
Hi. I am trying to find the cursor coordinates inside of a window, not a form. I would like to display the coordinates of the cursor when you click inside of the window. Either that, or have the...
1
by: Ian Davies | last post by:
I think javascript ans CSS is the solution for my problem. I wish to use them to retreive the relative coordinates of an element on webpage and store it in an text field on pressing a button. or...
2
by: Axel Gallus | last post by:
Is there a possibility to find out the coordinates, relative to the whole screen, or at least relative to the browsewindow, where an element ( e.g. link or picture ) begins or ends? Thx ...
1
by: jojoba | last post by:
Hi I am trying to determine coordinates of something in a webpage. All i have is a subset of html that i know exists in a given webpage. Now i want to find that subsetHtml in the page and...
10
by: sklett | last post by:
I have a situation where I'm getting in Image that has a gray (solid, same color) background with a smaller white rectangle inside. The position is not always the same. What I need to do is...
11
by: devnew | last post by:
hello while trying to write a function that processes some numpy arrays and calculate euclidean distance ,i ended up with this code (though i used numpy ,i believe my problem has more to do with...
7
by: stevewy | last post by:
I'm looking to manipulate/check the state of various checkboxes and radios in a form. Because I don't want to access all of the checkboxes in the form, only a specific section, I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.