Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code uses a custom function to resize the background image.
$(function(){
// Trigger maximage
jQuery('#maximage').maximage({
cssBackgroundSize: false,
backgroundSize: function( $item ){
// Contain portrait but cover landscape
if ($item.data('h') > $item.data('w')) {
if ($.Window.data('w') / $.Window.data('h') < $item.data('ar')) {
$item
.height(($.Window.data('w') / $item.data('ar')).toFixed(0))
.width($.Window.data('w'));
} else {
$item
.height($.Window.data('h'))
.width(($.Window.data('h') * $item.data('ar')).toFixed(0));
}
} else {
if ($.Window.data('w') / $.Window.data('h') < $item.data('ar')) {
$item
.height($.Window.data('h'))
.width(($.Window.data('h') * $item.data('ar')).toFixed(0));
} else {
$item
.height(($.Window.data('w') / $item.data('ar')).toFixed(0))
.width($.Window.data('w'));
}
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.