Skip to content

Commit e8f4629

Browse files
mmurrayjeresig
authored andcommitted
Offset setter for fixed position elements in Webkit. Fixes #8316.
1 parent 1912ded commit e8f4629

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/offset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ jQuery.offset = {
181181
curOffset = curElem.offset(),
182182
curCSSTop = jQuery.css( elem, "top" ),
183183
curCSSLeft = jQuery.css( elem, "left" ),
184-
calculatePosition = (position === "absolute" && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1),
184+
calculatePosition = ((position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1),
185185
props = {}, curPosition = {}, curTop, curLeft;
186186

187-
// need to be able to calculate position if either top or left is auto and position is absolute
187+
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
188188
if ( calculatePosition ) {
189189
curPosition = curElem.position();
190190
}

test/unit/offset.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,21 @@ test("offsetParent", function(){
422422
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
423423
});
424424

425+
testoffset("bug_8316", function( jQuery ){
426+
expect(2);
427+
428+
var tests = [
429+
{ id:'#elem', top: 100, left: 100 }
430+
];
431+
432+
jQuery.each(tests, function(){
433+
var el = jQuery(this.id);
434+
el.offset({ top: this.top, left: this.left});
435+
equals(Math.round(el.offset().top), this.top);
436+
equals(Math.round(el.offset().left), this.left);
437+
});
438+
});
439+
425440
function testoffset(name, fn) {
426441

427442
test(name, function() {
@@ -447,7 +462,7 @@ function testoffset(name, fn) {
447462
function loadFixture() {
448463
var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ),
449464
iframe = jQuery('<iframe />').css({
450-
width: 500, height: 500, position: 'absolute', top: -600, left: -600, visiblity: 'hidden'
465+
width: 500, height: 500, position: 'absolute', top: -600, left: -600, visibility: 'hidden'
451466
}).appendTo('body')[0];
452467
iframe.contentWindow.location = src;
453468
return iframe;

0 commit comments

Comments
 (0)