Page auto-zoom script to fit with no scrollbars
To everybody who's interested,
here is a nice cross-browser script which will zoom the page in case it is
designed for a minimum resolution. The script will zoom the page to fit the width of the window so that the user does not have to scroll the page to the right or to the left.
minW is the minimum width for your homepage to look good.
divWrap is a DIV with which you should wrap your entire homepage.
This script will also work when the window is resized.
<script type="text/javascript">
var minW = 1200;
$(function () {
CheckSizeZoom()
$('#divWrap').css('visibility', 'visible');
});
$(window).resize(CheckSizeZoom)
function CheckSizeZoom() {
if ($(window).width() < minW) {
var zoomLev = $(window).width() / minW;
if (typeof (document.body.style.zoom) != "undefined") {
$(document.body).css('zoom', zoomLev);
}
else {
// Mozilla doesn't support zoom, use -moz-transform to scale and compensate for lost width
$('#divWrap').css('-moz-transform', "scale(" + zoomLev + ")");
$('#divWrap').width($(window).width() / zoomLev + 10);
$('#divWrap').css('position', 'relative');
$('#divWrap').css('left', (($(window).width() - minW - 16) / 2) + "px");
$('#divWrap').css('top', "-19px");
$('#divWrap').css('position', 'relative');
}
}
else {
$(document.body).css('zoom', '');
$('#divWrap').css('position', '');
$('#divWrap').css('left', "");
$('#divWrap').css('top', "");
$('#divWrap').css('-moz-transform', "");
$('#divWrap').width("");
}
}
</script>
This is just what I've been looking for!
For a while I've wanted to be able to automatically fit the width of a website to the browser window, just as in a pdf, on a smartphone and in the Chrome plugin Zoomy (https://chrome.google.com/webstore/d...mdgfkjimojblie).
But unfortunately I have very little code knowledge and can't make the script work :/ I have set up a test page here: http://fitwidthtest.comeze.com/ and hope you can tell me what i've done wrong. The content simply remain invisible, which I guess indicates that the script is not loaded. Here it is again, without the script: http://fitwidthtest.comeze.com/without_javascript.html.
Thanks in advance!