473,804 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

minimum x-coord of an image when clicked

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(e vent)" />

How to determine minimum x and minimum y in my script?

Thanks in advance!
Jul 23 '05 #1
2 1465
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.offsetHeigh t ,
'\n offsetTop = ' + ele.offsetTop ,
'\n offsetLeft = ' + ele.offsetLeft ,
'\n offsetParent = ' + ele.offsetParen t ,
'\n offsetParent offsetTop = ',
ele.offsetParen t.offsetTop ,
'\n offsetParent offsetLeft = ' ,
ele.offsetParen t.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
Jul 23 '05 #2
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.
Jul 23 '05 #3

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

Similar topics

4
6079
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 this: private static final int DEFAULT_MINIMUM_LENGTH = ??????
1
1564
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 minimum machine requirements (processor speed & memory) will rule out too much of our target market (the universe of Windows users, well at least W98+ users). Our primary question is what is the minimum specification of a machine to run a...
1
4585
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? Thanks, VKG
3
9085
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, V2 up to V9 that I want to find the minimum value for each record. The values are decimal floating point numbers, some of the columns contain zeros but I want to ignore those and get the minimum non-zero number. I know how to do column sorting,...
3
13038
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
12
16921
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 there is not a one to one map between a session and a physical TCP connection. A client may disconnect the TCP connection if it is idle for more than 60 seconds... yet a conceptual "session" may last for days at a time. It's necessary that the...
3
1482
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 database server for caches that are frequently invalidated and a database retrieval is required. I want to be able to keep the cache and use it within a specified small period of time (the minimum cache time mentioned above). thanks, Joseph
11
8787
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 list of lists. Thanks, Josh
13
2756
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?
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.