Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created October 14, 2014 05:21
Show Gist options
  • Save RyoSugimoto/14827ad4524778944297 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/14827ad4524778944297 to your computer and use it in GitHub Desktop.
background-positionを取得するjQueryメソッド。
;(function () {
$.fn.getBgPosition = function () {
var $elm = $(this).eq(0);
var defVal = $elm.css('background-position');
var positions = {};
if (defVal) {
var valAry = defVal.split(' ');
positions = {
x: parseInt(valAry[0], 10),
y: parseInt(valAry[1], 10)
};
} else {
positions = {
x: parseInt($elm.css('background-position-x')),
y: parseInt($elm.css('background-position-y'))
};
}
return positions;
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment