Skip to content

Instantly share code, notes, and snippets.

@ProtoJazz
Last active November 10, 2015 19:36
Show Gist options
  • Select an option

  • Save ProtoJazz/7c9470c02ba94e682039 to your computer and use it in GitHub Desktop.

Select an option

Save ProtoJazz/7c9470c02ba94e682039 to your computer and use it in GitHub Desktop.
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
var alsoenlarge = true;
$(function(){
if(isScalePossible()){
$('body').css({overflow:'hidden'});
$('#scalecontainer').css({position: 'absolute', margin: 0});
// Run scale function on start
scaleSite();
scaleSite();
// Run scale function on browser resize
$(window).resize(scaleSite);
}
});
function scaleSite()
{
containerw = window.innerWidth * 0.5; /* The width of the div, currently set to half of the window's width */
containerh = 600; /* The maximum possible height of the div; the recommend size for this is equal to or larger than the H of the element. */
sitew = $('#scalecontainer').width();
siteh = $('#scalecontainer').height();
f = containerw/sitew;
f = containerh/siteh<f?containerh/siteh:f;
if(!alsoenlarge && f>1) f = 1;
$('#scalecontainer').css({
"-moz-transform" : "scale("+f+")",
"-webkit-transform" : "scale("+f+")",
"-ms-transform" : "scale("+f+")",
"-o-transform" : "scale("+f+")",
"transform" : "scale("+f+")",
"left" : ((containerw-(sitew*f))/2)+"px",
"top" : "0px"
});
}
function isScalePossible()
{
can = 'MozTransform' in document.body.style;
if(!can) can = 'webkitTransform' in document.body.style;
if(!can) can = 'msTransform' in document.body.style;
if(!can) can = 'OTransform' in document.body.style;
if(!can) can = 'transform' in document.body.style;
if(!can) can = 'Transform' in document.body.style;
return can;
}
</script>
<style>#scalecontainer{
-moz-transform-origin: center top;
-webkit-transform-origin: center top;
-ms-transform-origin: center top;
-o-transform-origin: center top;
transform-origin: center top;
width: 800px;
min-width: 100%
margin: 0 auto;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment