Skip to content

Instantly share code, notes, and snippets.

@laurentperroteau
Last active August 29, 2015 14:06
Show Gist options
  • Save laurentperroteau/a6ca0a9fa6da2066f16e to your computer and use it in GitHub Desktop.
Save laurentperroteau/a6ca0a9fa6da2066f16e to your computer and use it in GitHub Desktop.
Center backgroud with JavaScript (need jQuery)
centerBackground: function () {
if( !mobile )
{
var $back = $('#back-img img');
var backSize = tablet ? 750 : 1490;
if( backSize >= Master.data.w )
{
var decalage = ( Master.data.w - backSize) / 2;
$back.css('marginLeft', decalage);
}
else {
$back.css('marginLeft', 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment