/ Published in: jQuery
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<script type="text/javascript">
//<![CDATA[
function getBackgroundPos(obj) {
var pos = obj.css("background-position");
if (pos == 'undefined' || pos == null) {
pos = [obj.css("background-position-x"),obj.css("background-position-y")];//i hate IE!!
} else {
pos = pos.split(" ");
}
return {
x: parseFloat(pos[0]),
xUnit: pos[0].replace(/[0-9-.]/g, ""),
y: parseFloat(pos[1]),
yUnit: pos[1].replace(/[0-9-.]/g, "")
};
}
$(document).ready(function() {
// Test:
// getBackgroundPos($("body")).x
// getBackgroundPos($("body")).xUnit
// getBackgroundPos($("body")).y
// getBackgroundPos($("body")).yUnit
//
});
//]]>
</script>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                