Bug Tracker

Opened 15 years ago

Closed 14 years ago

Last modified 11 years ago

#2082 closed bug (fixed)

Offset function returns wrong value with IE7/position fixed

Reported by: dprunier Owned by: brandon
Priority: major Milestone: 1.2.2
Component: offset Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:


When querying the offset top of a fixed div in IE7, the scroll is mistakenly counted in the returned value.


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<script type="text/javascript" src="js/jquery.js" ></script>
		<script type="text/javascript">
		$(document).ready(function() {
			setInterval(function() {
			}, 100);
		<div id="fixed" style="position: fixed; 
		                       top: 0px; left: 0px; 
		                       width: 100px; height: 100px; 
		                       background-color: fuchsia;">
		<div id="big" style="height: 5000px">

Change History (8)

comment:1 Changed 15 years ago by brandon

Resolution: fixed
Status: newclosed

This is fixed in the latest SVN.

comment:2 Changed 15 years ago by dprunier

Resolution: fixed
Status: closedreopened

The test sample in the description still doesn't work. This is actually broken in both IE7 and FF now (1.2.2, r4454).

comment:3 Changed 15 years ago by brandon

Resolution: fixed
Status: reopenedclosed

This is fixed. Please see the modified test case that places a div at the elements location here: http://brandonaaron.net/jquery/tickets/2082/test.html

If the scroll offset is not included then the marker div will not be placed correctly.

This was fixed for all supported browsers in 1.2.2. There is also now an offset test suite that can be found in test/offset.html

comment:4 Changed 15 years ago by manolofdez85

Resolution: fixed
Status: closedreopened

Is this bug really fixed??

I tried the following and still does not work

html, body{
<script type="text/javascript" src="js/jquery.js">void(0);</script>
<script type="text/javascript">
			var offset = $(this).offset();
			alert("Wrong: " + offset.left + ", " + offset.top)
			alert("Write: " + $(this).get(0).offsetLeft + ", " + $(this).get(0).offsetTop)


<img src="http://images.google.com/intl/en_ALL/images/images_hp.gif" />


Thanks in advance!!

comment:5 Changed 14 years ago by dmethvin

Owner: set to brandon
Status: reopenednew

Confirmed that the test case returns "Wrong: 2,2" "Right: 0, 0" for the test case above.

comment:6 Changed 14 years ago by dmethvin

Test case broken for IE7...

comment:7 Changed 14 years ago by dmethvin

Component: coreoffset

comment:8 Changed 14 years ago by brandon

Resolution: fixed
Status: newclosed

This is fixed and has been fixed for a very long time now.

You can't just compare offsetLeft and offsetTop to the _actual_ offset of an element. The offset of an element is its position from the top left of the document. Please see the following test case to hopefully better understand. http://jquery.com/test/data/offset/fixed.html

Click either other two white boxes and a marker will be placed on top of the element you clicked. This is the true offset ... not its offsetLeft and offsetTop which shouldn't even be trusted for relative offset.

Note: See TracTickets for help on using tickets.