简体   繁体   中英

Slimbox2 fit to window - CSS, jQuery

I'm using Slimbox2 for my galleries but there is missing one important feature - resize frame to fit the screen. When image is too large it goes beyond the screen. Is there anyone who found solution for that ?

Plugin official site

Api documentation

Fixing this is really important for me, thanks in advance !

I had the same problem and i did that:

I Opened slimbox2.js file and i replaced:

$(image).css({backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: ""});
$(sizer).width(preload.width);
$([sizer, prevLink, nextLink]).height(preload.height);

with:

     /* make sure the image won't be bigger than the window */
window.innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; //ie fix
window.innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //ie fix        
var winWidth =  window.innerWidth-200; //browser width
var winHeight = window.innerHeight-100; //browser height
var my_w = preload.width; //original width
var my_h = preload.height; //original height

    // scale  width
    var scaleW1 = winWidth;
    var scaleH1 = (my_h * winWidth) / my_w;

    // scale  height
    var scaleW2 = (my_w * winHeight) / my_h;
    var scaleH2 = winHeight;
    var scale = (scaleW2 > winWidth);

    if (scale) {
        reswidth = Math.floor(scaleW1);
        resheight = Math.floor(scaleH1);

    }
    else {
        reswidth = Math.floor(scaleW2);
        resheight = Math.floor(scaleH2);

    }
    if ($("p").hasClass("slimboxie")){ 
    $(image).css({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader( src='"+ activeURL + "', sizingMethod='scale')", visibility: "hidden", display: ""});

    $(sizer).width(reswidth);
    $([sizer, prevLink, nextLink]).height(resheight); }
    else {

    $(image).css({backgroundImage: "url(" + activeURL + ")", backgroundSize: reswidth + "px " + resheight + "px", visibility: "hidden", display: ""});
    $(sizer).width(reswidth);
    $([sizer, prevLink, nextLink]).height(resheight); 

    }

Im an amateur so be kind :) if you have questions about fixing it in ie ask me :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM