Bug Tracker

Ticket #74 (closed enhancement: fixed)

Opened 2 years ago

Last modified 1 year ago

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

Reported by: peter.goodman@… Assigned to: anonymous
Type: enhancement Priority: minor
Milestone: Component: core
Version: Keywords: css,top,left
Cc: Needs:

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

Change History

Changed 2 years ago by dave.methvin@…

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 2 years ago by john

  • version deleted
  • milestone deleted

Changed 2 years ago by brandon

  • status changed from new to closed
  • resolution set to fixed

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.

Note: See TracTickets for help on using tickets.