Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#11542 closed bug (fixed)

body.offset() is assumed always 0,0

Reported by: atirip Owned by:
Priority: low Milestone: None
Component: offset Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


jQuery assumes that body.offset() is always {0,0}, but this is wrong.


<!DOCTYPE html>
<title> jquery position bug</title>
html {
	background: #3F434C;
	height: 100%;
body {
	width: 100%;
	max-width: 640px;
	min-width: 320px;
	height: 100%;
	margin: 0 auto;
	background: #DDD;
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
		alert( $('div').position().left );

Expected result for alert is 0 (for windows wider than 640px), but depending on window width, real body.offset.left is returned.

Proposed fix: assume body as normal html element in offset module

Change History (5)

comment:1 Changed 11 years ago by sindresorhus

Component: unfiledoffset
Priority: undecidedlow
Status: newopen

Please read the text in the red box and provide a testcase on jsfiddle the next time. Thanks :)

Simplified testcase: http://jsfiddle.net/wSFTd/

comment:2 Changed 10 years ago by gibson042

Keywords: 1.9-discuss added

comment:3 Changed 10 years ago by mikesherov

+1, I'm weary of people who are fitzing with body, but we should investigate.

comment:4 Changed 10 years ago by Daniel Gálvez

Resolution: fixed
Status: openclosed

Fix #11542. document.body should not be special in .offset() and document.documentElement is the default element.offsetParent. Close gh-899.

Changeset: b398a68333d5eb9859fabb1ceabe84a1a753760a

comment:5 Changed 10 years ago by dmethvin

Keywords: 1.9-discuss removed
Note: See TracTickets for help on using tickets.