Skip to main content

Bug Tracker

Side navigation

#74 closed enhancement (fixed)

Opened July 16, 2006 09:16PM UTC

Closed October 08, 2006 01:32AM UTC

Last modified March 15, 2012 12:56PM UTC

css('top') and css('left')

Reported by: peter.goodman@gmail. Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: css,top,left Cc:
Blocked by: Blocking:
Description

It would be really cool for jquery to make an exception for css('top') and css('left') where if they are not set or if they are set to auto it will find them. I've been forced to extend jquery to get the desirec effect:

get the top position of an element

$.fn.postop = function() {

var postop = 0;

var obj = this.get(0);

while(obj && obj != null) {

postop += obj.offsetTop; - obj.scrollTop

obj = obj.offsetParent;

}

return postop;

}

// get the left position of an element

$.fn.posleft = function() {

var posleft = 0;

var obj = this.get(0);

if(obj) {

posleft = obj.offsetLeft;

while((obj = obj.offsetParent) != null) {

posleft += obj.offsetLeft;

}

}

return posleft;

}

Attachments (0)
Change History (4)

Changed August 03, 2006 04:07PM UTC by dave.methvin comment:1

I agree it would be useful to have a .top() and .left() that did the heroics needed to get reasonable values, but I don't want it to be at the expense of .css(). Otherwise it's impossible to see what values the CSS really had there. Already with $().css('width', '20em') you do not get '20em' back from .css('width').

Changed August 06, 2006 07:11PM UTC by john comment:2

milestone: 1.0
version: 1.0b1

Changed October 08, 2006 01:32AM UTC by brandon comment:3

resolution: → fixed
status: newclosed

This is now available through the $().offset() method in dimensions.js. Modifying the $().css() method would result in unexpected behavior for those expecting the actual css value of top or left.

Changed November 24, 2011 10:17AM UTC by anonymous comment:4

nyumburgány