JavaScriptでCSSのbackground-positionの値を取得
IEとFirefoxで取得方法が異なる。 elem = document.getElementsById(“hoge”) でエレメントを取得後、IEだと、 elem.currentStyle[“backgroundPositionX”] elem.currentStyle[“backgroundPositionY”] で、firefoxだと、 document.defaultView.getComputedStyle(elem, ‘’).getPropertyValue(“background-position”) で、 “50% 50%“という感じで取得できるので、split等にて分割して取得。 下記のサンプルは、#hogeのbackground-positionのY軸が設定されていないか、0の場合、20px開始位置を下にずらす。 ...