colorbox icon indicating copy to clipboard operation
colorbox copied to clipboard

Width and height doesn't support vw or vh units

Open LPGhatguy opened this issue 10 years ago • 1 comments

This snippet creates a colorbox of max width and height 90px instead of 90vw and 90vh.

$(".gallery a").colorbox({
    maxWidth: "90vw",
    maxHeight: "90vh"
});

LPGhatguy avatar Jun 12 '15 19:06 LPGhatguy

I came out here from Google myself...

Solution (quick 'n' dirt hack):

Find in jquery.colorbox.js

function setSize(size, dimension) {
    return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10));
}

replace by:

function setSize(size, dimension) {
		return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10)) *
			Math.round((/vw/.test(size) ? (document.documentElement.clientWidth / 100) : 1)) *
			Math.round((/vh/.test(size) ? (document.documentElement.clienHeight / 100) : 1));
	}

(vw/vh calculation from https://stackoverflow.com/a/28295133/151150 )

Shelim avatar Jan 22 '21 09:01 Shelim