#74 closed enhancement (fixed)
css('top') and css('left')
Reported by: | 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;
}
Change History (4)
comment:1 Changed 17 years ago by
comment:2 Changed 17 years ago by
Milestone: | 1.0 |
---|---|
Version: | 1.0b1 |
comment:3 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.
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').