Created
October 14, 2014 05:21
-
-
Save RyoSugimoto/14827ad4524778944297 to your computer and use it in GitHub Desktop.
background-positionを取得するjQueryメソッド。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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