mootools/mootools-core — Issue #2213: getting a background-position
Author: ibolmo
Created: 2012-01-19 07:49:30+00:00
State: open
Labels: bug, enhancement

(from [Lighthouse](https://mootools.lighthouseapp.com/projects/2706/tickets/151-getting-a-background-position))

If you set a background-position via CSS for a element in Firefox 2, element.getStyle('background-position') returns nothing.

It works in Firefox 3 + Safari.

----

(from [comment](https://mootools.lighthouseapp.com/projects/2706/tickets/151-getting-a-background-position#ticket-151-10))

Yes, this is the same patch as Fabian posted above. I'd add a lookup for named values so you consistently get either percentages or pixels (like the modern browsers do).

``` javascript
var namedPositions = { left: '0%', top: '0%', center: '50%', right: '100%', bottom: '100%' };
function getBackgroundPosition(el){
if (Browser.Engine.trident){
var x = el.getStyle('background-position-x'), y = el.getStyle('background-position-y');
return (namedPositions[x] || x) + ' ' + (namedPositions[y] || y);
} else {
return el.getStyle('background-position');
}
}
```

This seems like a nice addition.
Now, conversion between percentages and pixels require that you know the size of the background-image, which requires it to load first. That makes it essential unfeasible. The addition of further options in CSS3 makes it even more complex. So, unit conversion is a won't fix for background-position.