Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 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:

Description

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

http://bkp.ee/atirip/bugs/jbug.html

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

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 7 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 7 years ago by gibson042

Keywords: 1.9-discuss added

comment:3 Changed 7 years ago by mikesherov

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

comment:4 Changed 7 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 7 years ago by dmethvin

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