Last active
September 12, 2023 22:40
-
-
Save ridwanzal/b7c050494eaad781a09dc60225e264c1 to your computer and use it in GitHub Desktop.
Useful javascript behaviour
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
/* | |
* @param el is jquery element | |
*/ | |
function adjustPosition(el){ | |
var $el = $(el); | |
if (!$el.hasClass('adjusted')) { | |
var _dataX = $el.data('position-x'); | |
var _dataY = $el.data('position-y'); | |
var positionX = _dataX ? _dataX + '%' : 'center'; | |
var positionY = _dataY ? _dataY + '%' : 'center'; | |
$el.css('background-position', positionX + ' ' + positionY); | |
$el.addClass('adjusted'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment