Bug Tracker

Modify

Ticket #1834 (closed bug: wontfix)

Opened 6 years ago

Last modified 5 years ago

event.clientX and clientY incorrect for Safari2

Reported by: jeffkretz Owned by:
Priority: major Milestone: 1.2.2
Component: event Version: 1.2.1
Keywords: Cc:
Blocking: Blocked by:

Description

This is factually a bug/incompatibility in Safari, but the event normalization done in jQuery can address this issue.

For IE6, IE7, FF and Safari, on a click event, the clientX and clientY values are relative to the top left of the viewport. For Safari 2, they are relative to the top left of the document.

If you scroll down or to the right, the clientX and clientY for Safari is different from all the other browsers.

Sample page here:

 http://www.scorpiontechnology.com/cobalt/mouseclick.htm

One fix would be to add this right after the pageX/Y normalization script under the event.fix method:

// Fix clientX/Y for Safari.
if (jQuery.browser.safari) {
	var doc = document.documentElement, body = document.body;
	event.clientX = event.clientX - (doc && doc.scrollLeft || body && body.scrollLeft || 0) + (doc.clientLeft || 0);
	event.clientY = event.clientY - (doc && doc.scrollTop  || body && body.scrollTop  || 0) + (doc.clientLeft || 0);
}

This can be seen working on this page:

 http://www.scorpiontechnology.com/cobalt/mouseclick_fix.htm

JK

Change History

comment:1 Changed 6 years ago by jeffkretz

Correction:

For IE6, IE7, FF and Opera, on a click event ...

comment:2 Changed 5 years ago by joern

  • Component changed from core to event

comment:3 Changed 5 years ago by brandon

  • Status changed from new to closed
  • Resolution set to wontfix

This is resolved in Safari 3

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.