Skip to content

Instantly share code, notes, and snippets.

@ridwanzal
Last active September 12, 2023 22:40
Show Gist options
  • Save ridwanzal/b7c050494eaad781a09dc60225e264c1 to your computer and use it in GitHub Desktop.
Save ridwanzal/b7c050494eaad781a09dc60225e264c1 to your computer and use it in GitHub Desktop.
Useful javascript behaviour
/*
* @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