Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The code used to make offsets with Maximage 2.0.
$(function(){
// Trigger maximage
jQuery('#maximage').maximage({
cssBackgroundSize: false, // We don't want to use background-size:cover for our custom size
backgroundSize: function( $item ){
var verticalOffset = 200, // Top offset + Bottom offset
horizontalOffset = 200; // Left offset + Right offset
if($.Window.data('w') / $.Window.data('h') < $item.data('ar')){ // Image size based on height
$item
.height((($.Window.data('w') - horizontalOffset) / $item.data('ar')).toFixed(0))
.width($.Window.data('w') - horizontalOffset);
}else{ // Image size based on width
$item
.height($.Window.data('h') - verticalOffset)
.width((($.Window.data('h') - verticalOffset) * $item.data('ar')).toFixed(0));
}
},
onImagesLoaded: function(){
jQuery('#maximage').fadeIn();
}
});
});
.curtains {
height:100%;
left:0;
position:absolute;
top:0;
width:100%;
z-index:99;
}
.curtains span {
background:#fff;
position:absolute;
}
.curtains .top {
height:100px;
left:0;
top:0;
width:100%;
}
.curtains .right {
height:100%;
right:0;
top:0;
width:100px;
}
.curtains .bottom {
bottom:0;
height:100px;
left:0;
width:100%;
}
.curtains .left {
height:100%;
left:0;
top:0;
width:100px;
}
<div class="curtains">
<span class="top"></span>
<span class="right"></span>
<span class="bottom"></span>
<span class="left"></span>
</div>
<div id="maximage">
<img src="../lib/images/demo/oldmanb.jpg" width="1422" height="1800" alt="Oldmanb">
<img src="../lib/images/demo/test1.jpg" width="1095" height="730" alt="Test1">
<img src="../lib/images/demo/test2.jpg" width="1158" height="869" alt="Test2">
<img src="../lib/images/demo/test3.jpg" width="1600" height="1200" alt="Test3">
</div>
$(function(){
// Trigger maximage
jQuery('#maximage').maximage({
cssBackgroundSize: false, // We don't want to use background-size:cover for our custom size
backgroundSize: function( $item ){
var verticalOffset = 200, // Top offset + Bottom offset
horizontalOffset = 200; // Left offset + Right offset
if($.Window.data('w') / $.Window.data('h') < $item.data('ar')){ // Image size based on height
$item
.height($.Window.data('h') - verticalOffset)
.width((($.Window.data('h') - verticalOffset) * $item.data('ar')).toFixed(0));
}else{ // Image size based on width
$item
.height((($.Window.data('w') - horizontalOffset) / $item.data('ar')).toFixed(0))
.width($.Window.data('w') - horizontalOffset);
}
},
onImagesLoaded: function(){
jQuery('#maximage').fadeIn();
}
});
});
@alecvannoten

This comment has been minimized.

Copy link

alecvannoten commented Jul 4, 2014

hi is it possible to only set a top offset?
so no left, right and bottom offset?

@marcoledelicanasah

This comment has been minimized.

Copy link

marcoledelicanasah commented Feb 10, 2016

Sir its really excellent code !! But can you give a code that is just simple to understand for a beginner programming..

@whoaitsaimz

This comment has been minimized.

Copy link

whoaitsaimz commented Oct 12, 2016

This doesn't seem to work unless the img elements are a direct child of #maximage.

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.