w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});
w(p).width(k.width);
w([p,I,d]).height(k.height);
withvar winWidth = $(window).innerWidth() - 20; var winHeight = $(window).innerHeight() - 120; /* determine proper w and h for img, based on original image's dimensions and window size */ var my_w = k.width; var my_h = k.height; if (my_h > my_w) { my_w = my_w/my_h*winHeight; my_h = winHeight; } else { my_h = my_h/my_w*winWidth; my_w = winWidth; } if (k.width > my_w || k.height > my_h){ /* constrain it */ w(g).css({backgroundImage:"url("+n+")",backgroundSize:""+my_w+"px "+my_h+"px",visibility:"hidden",display:""}); w(p).width(my_w); w([p,I,d]).height(my_h); } else { /* default behavior NORMAL before hacking */ w(g).css({backgroundImage:"url("+n+")",backgroundSize:"",visibility:"hidden",display:""}); w(p).width(k.width); w([p,I,d]).height(k.height); }
That's interesting. I have programmed it slightly differently in our version of Slimbox 2.0.5, which also has a timed slide show option. It is in use in a couple of cricket club websites and works fine on both desktop and smartphone. Image resizing has allowed us to use Slimbox to display scoresheet photos as well as the normal usage in photo galleries.
Change:
function animateBox() {
center.className = "";
$(image).css({backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: ""});
$(sizer).width(preload.width);
$([sizer, prevLink, nextLink]).height(preload.height);
to:
// 06.07.2014 JPL Resize images (based on BeNoGa www.ISNO.ch 02.06.2013, but with revised scaling)
function animateBox() {
var vpw, vph, plw, plh, rsw, rsh, rsz;
center.className = "";
vpw = vpWidth() - options.bdrw; // size of current window less Slimbox border
vph = vpHeight() - options.bdrh;
plw = preload.width; // image size
plh = preload.height;
//console.log("vpw x vph: " + vpw + "x" + vph + "\nplw x plh: " + plw + "x" + plh);
if ((plw > vpw) || (plh > vph)) {
rsw = vpw / plw;
rsh = vph / plh;
rsz = (rsw < rsh) ? rsw : rsh;
plw = Math.floor(plw * rsz);
plh = Math.floor(plh * rsz);
//console.log("Resized: " + plw + "x" + plh + " [" + rsz + "]");
$(image).css({
backgroundImage: "url(" + activeURL + ")",
backgroundSize: "" + plw + "px " + plh + "px",
visibility: "hidden",
display: "block"
});
} else {
//console.log("Unchanged: " + plw + "x" + plh);
$(image).css({
backgroundImage: "url(" + activeURL + ")",
visibility: "hidden",
display: ""
});
}
$(sizer).width(plw);
$([sizer, prevLink, showLink, nextLink]).height(plh);
$('#lbImage').css('background-size', 'contain');
New options items:
bdrw: 20, // border = 2x10px
bdrh: 60, // border = 2x10px + allowance for caption & counter
Functions used to get viewport size:
function vpWidth() {
var objNode = document.createElement("div");
objNode.style.position = 'fixed';
objNode.style.width = '100%';
objNode.style.height = '100%';
document.body.appendChild(objNode);
vpWidth = objNode.offsetWidth;
document.body.removeChild(objNode);
return vpWidth;
};
function vpHeight() {
var objNode = document.createElement("div");
objNode.style.position = 'fixed';
objNode.style.width = '100%';
objNode.style.height = '100%';
document.body.appendChild(objNode);
vpHeight = objNode.offsetHeight;
document.body.removeChild(objNode);
return vpHeight;
};
JPL
function animateBox() {center.className = "";$(image).css({backgroundImage: "url(" + activeURL + ")", visibility: "hidden", display: ""});$(sizer).width(preload.width);$([sizer, prevLink, nextLink]).height(preload.height);
// 06.07.2014 JPL Resize images (based on BeNoGa www.ISNO.ch 02.06.2013, but with revised scaling)function animateBox() {var vpw, vph, plw, plh, rsw, rsh, rsz;center.className = "";
vpw = LIB1.vpWidth() - options.bdrw; // size of current window less Slimbox bordervph = LIB1.vpHeight() - options.bdrh;
plw = preload.width; // image sizeplh = preload.height;//console.log("vpw x vph: " + vpw + "x" + vph + "\nplw x plh: " + plw + "x" + plh);if ((plw > vpw) || (plh > vph)) {rsw = vpw / plw;rsh = vph / plh;rsz = (rsw < rsh) ? rsw : rsh;plw = Math.floor(plw * rsz);plh = Math.floor(plh * rsz);//console.log("Resized: " + plw + "x" + plh + " [" + rsz + "]");$(image).css({backgroundImage: "url(" + activeURL + ")",backgroundSize: "" + plw + "px " + plh + "px",visibility: "hidden",display: "block"});} else {//console.log("Unchanged: " + plw + "x" + plh);$(image).css({backgroundImage: "url(" + activeURL + ")",visibility: "hidden",display: ""});}$(sizer).width(plw);
$([sizer, prevLink, nextLink]).height(plh);
$('#lbImage').css('background-size', 'contain');
bdrw: 20, // border = 2x10pxbdrh: 60, // border = 2x10px + allowance for caption & counter
var LIB1 = LIB1 || {};(function (document, LIB1) {"use strict";function vpWidth() {var objNode, w1;
objNode = document.createElement("div");objNode.style.position = 'fixed';objNode.style.width = '100%';objNode.style.height = '100%';document.body.appendChild(objNode);
w1 = objNode.offsetWidth;document.body.removeChild(objNode);return w1;}LIB1.vpWidth = vpWidth;function vpHeight() {var objNode, h1;
objNode = document.createElement("div");objNode.style.position = 'fixed';objNode.style.width = '100%';objNode.style.height = '100%';document.body.appendChild(objNode);
h1 = objNode.offsetHeight;document.body.removeChild(objNode);return h1;}LIB1.vpHeight = vpHeight;}(document, LIB1));