Created
April 14, 2014 01:49
-
-
Save marcelaraujo/10610335 to your computer and use it in GitHub Desktop.
jQuery window resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get size of viewport */ | |
layout.winWidth = $(window).width(); | |
layout.winHeight = $(window).height(); | |
/* Get available width by subtracting the size of the rest of the components */ | |
var dwidth = layout.winWidth - 63; | |
var dheight = layout.winHeight - 111; | |
/* Check if scrollbars are needed (cheight and cwidth are canvas element's height and width)*/ | |
var vScrollNeeded = dheight < app.cheight; | |
var hScrollNeeded = dwidth < app.cwidth; | |
/* Final width */ | |
var fwidth; | |
var fheight; | |
/* If the available width is greater than the size of the canvas + size of the scrollbars, if | |
they're needed, set it to the size of the canvas + size of the scrollbars (if they're needed). | |
Otherwise, set it to the available space. */ | |
if (dwidth > app.cwidth + (vScrollNeeded?layout.scrollWidth:0)) { | |
fwidth = app.cwidth + (vScrollNeeded?layout.scrollWidth:0); | |
} else { | |
fwidth = dwidth; | |
} | |
/* Same with vertical height */ | |
if (dheight > app.cheight + (hScrollNeeded?layout.scrollWidth:0)) { | |
fheight = app.cheight + (hScrollNeeded?layout.scrollWidth:0); | |
} else { | |
fheight = dheight; | |
} | |
$(layout.canvas).width(fwidth); | |
$(layout.canvas).height(fheight); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment