/ Published in: jQuery
Creating sprite buttons often had problems with different browsers.
This is a solution to get background positions in each browser for further manipulation.
This is a solution to get background positions in each browser for further manipulation.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getBgPos(oObj) { var aPosXY = false; try { aPosXY = oObj.css('background-position').replace(/px/g, '').split(' '); aPosXY[0] = parseInt(aPosXY[0]); aPosXY[1] = parseInt(aPosXY[1]); } catch(error) { var aPosX = oObj.css("background-position-x").split('px'); var aPosY = oObj.css("background-position-y").split('px'); aPosXY = new Array(parseInt(aPosX[0]), parseInt(aPosY[0])); } return aPosXY; }