Bug Tracker

Modify

Ticket #11542 (closed bug: fixed)

Opened 14 months ago

Last modified 7 months ago

body.offset() is assumed always 0,0

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

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

comment:1 Changed 14 months ago by sindresorhus

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to offset

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 8 months ago by gibson042

  • Keywords 1.9-discuss added

comment:3 Changed 7 months ago by mikesherov

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

comment:4 Changed 7 months ago by Daniel Gálvez

  • Status changed from open to closed
  • Resolution set to fixed

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 months ago by dmethvin

  • Keywords 1.9-discuss removed

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.