When we click an image, we get the coordinates x and y in the event
handler, like this
<script type="text/javascript">
function fun2(evnt){
var e=evnt;
if (e==undefined){e=event;}
var x=e.x || e.layerX;
var y=e.y || e.layerY;
alert('x='+x+' y='+y';
return true;
}
</script>
....
<img src="test.jpg" onclick="fun2(event)" />
How to determine minimum x and minimum y in my script?
Thanks in advance! 2 1444
optimistx wrote: When we click an image, we get the coordinates x and y in the event handler, like this
<script type="text/javascript"> function fun2(evnt){ var e=evnt; if (e==undefined){e=event;} var x=e.x || e.layerX; var y=e.y || e.layerY; alert('x='+x+' y='+y'; return true; } </script>
Is this OK? Works in IE, Safari and Firefox:
<script type="text/javascript">
function fun2(evnt){
var e = evnt || window.event;
// I think the following line should be
// var ele = e.target || e.srcElement;
// for older IE but I can't test it right now
var ele = e.target;
var x = e.x || e.layerX;
var y = e.y || e.layerY;
var msg = [' Element clicked on: ' + ele.nodeName ,
' ' + ele ,
'\n Click location (x,y) = ' ,
'(' + x + ',' + y + ')',
'\n offsetWidth = ' + ele.offsetWidth ,
'\n offsetHeight = ' + ele.offsetHeight ,
'\n offsetTop = ' + ele.offsetTop ,
'\n offsetLeft = ' + ele.offsetLeft ,
'\n offsetParent = ' + ele.offsetParent ,
'\n offsetParent offsetTop = ',
ele.offsetParent.offsetTop ,
'\n offsetParent offsetLeft = ' ,
ele.offsetParent.offsetLeft ];
alert(msg.join(''));
}
</script>
[...] How to determine minimum x and minimum y in my script?
Exactly what do you mean by "minimum x and minium y"? If you
mean the position of the top left corner of the element clicked
on, then its position must be calculated carefully as each
browser handles it differently. Search through this newsgroup
for offsetParent.
There is a good discussion of the viewport, its properties and
browser support here:
<URL:http://www.quirksmode.org/js/>
Click on the viewport link - hope that helps.
--
Fred
Fred Oz wrote: There is a good discussion of the viewport, its properties and browser support here:
<URL:http://www.quirksmode.org/js/>
Click on the viewport link - hope that helps.
Thanks Fred,
that was exactly what was needed. A marvellous, useful site. You guessed
the top/left corner thingy right, too. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lobang Trader |
last post by:
Hi all,
I am trying to create a username and a password class.
I would like to know what are the RECOMMENDED minimum and maximum length
for both fields?
These fields will be something like...
|
by: Mitch Olson |
last post by:
Hi
our company is just about to embark on developing a PIM-type application and
would like to use .NET (VB6 is our distant option 2).
The question we are currently investigating is whether the...
|
by: Vikrant |
last post by:
On my DB2/UDB system, some tablespace 'Minimum recovery time' is
2000-11-19 or some '1999-10-04' or different, for some tablespace
theres is no 'Minimum recovery time' , what does it tell me?
...
|
by: RobG |
last post by:
I would like a query that will tell me the minimum non-zero value in a
row.
Say I have a table with a column called recordID that contains unique
record IDs, and have a set of values named V1,...
|
by: Sona |
last post by:
I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share some code with me
for doing this? Thanks
Sona
|
by: David Sworder |
last post by:
Hi,
I'm writing an application in which a client (C#/WinForms) and server
(C#/service) interact with one another. The client establishes a "session"
with the server but for scalability reasons...
|
by: Joseph |
last post by:
Has anyone implement a mechanism to retain the cache up to a minimum cache
time even though it is supposed to get invalidated? I asked this because I
don't want to increase the load on the...
|
by: JJLaRocque |
last post by:
Hi all,
Is there a simple python function to return the list index of the
minimum entry in a list of lists?
ie, for , , ] to return 2,4.
Or, same question but just for a list of numbers, not a...
|
by: Ioannis Vranos |
last post by:
Is there any mentioning in the standard of the number of bits of the
various built in types, apart from char/signed char/unsigned char types?
Or only about the minimum value ranges of them?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |