Skip to content

Instantly share code, notes, and snippets.

@AliMD
Last active December 10, 2018 18:44
Show Gist options
  • Save AliMD/5099197 to your computer and use it in GitHub Desktop.
Save AliMD/5099197 to your computer and use it in GitHub Desktop.
Liquid Auto Zoom window ;)
/*jshint strict:true, es5:true, forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, nonew:true, browser:true, devel:true, indent:2, boss:true, curly:false, immed:false, latedef:true, newcap:true, plusplus:false, trailing:true, maxparams:4, maxerr:100, debug:false, asi:false, evil:false, expr:true, eqnull:false, esnext:false, funcscope:false, globalstrict:false, loopfunc:false */
(function(pageWidth,pageHeight,px,py){
"use strict";
var prefix='',
iv = 0,
vendors = {Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' },
testEl = document.createElement('div'),
each = function(elements, callback){
for (var key in elements)
if (callback.call(elements[key], key, elements[key]) === false) return elements;
return elements;
},
winZoom = function(){
var paddingX = px || 0,
paddingY = py || 0,
winHeight = winHeight || window.innerHeight,
winWidth = winWidth || window.innerWidth,
container = document.querySelector('.container'),
scalex = Math.floor((winHeight-paddingY)/pageHeight*1000)/1000,
scaley = Math.floor((winWidth-paddingX)/pageWidth*1000)/1000,
scale = Math.min(scalex,scaley),
top = Math.round((winHeight-pageHeight*scale)/2),
left = Math.round((winWidth-pageWidth*scale)/2);
left = left>0 ? left : 0;
container.style.position = 'absolute';
container.style.left = left + 'px';
container.style.top = top + 'px';
container.style[prefix+'TransformOrigin']= "0 0";
container.style[prefix+'Transform'] = 'scale('+scale+')';
},
resize=function(){
if(iv) clearTimeout(iv);
iv = setTimeout(winZoom,300);
};
each(vendors, function(vendor, evt){
if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
prefix = vendor;
return false;
}
});
window.onresize = resize;
winZoom();
})(900,500,30,30);
(function(pageWidth,pageHeight,px,py){"use strict"
var prefix="",iv=0,vendors={Webkit:"webkit",Moz:"",O:"o",ms:"MS"},testEl=document.createElement("div"),each=function(elements,callback){for(var key in elements)if(callback.call(elements[key],key,elements[key])===!1)return elements
return elements},winZoom=function(){var paddingX=px||0,paddingY=py||0,winHeight=winHeight||window.innerHeight,winWidth=winWidth||window.innerWidth,container=document.querySelector(".container"),scalex=Math.floor(1e3*((winHeight-paddingY)/pageHeight))/1e3,scaley=Math.floor(1e3*((winWidth-paddingX)/pageWidth))/1e3,scale=Math.min(scalex,scaley),top=Math.round((winHeight-pageHeight*scale)/2),left=Math.round((winWidth-pageWidth*scale)/2)
left=left>0?left:0,container.style.position="absolute",container.style.left=left+"px",container.style.top=top+"px",container.style[prefix+"TransformOrigin"]="0 0",container.style[prefix+"Transform"]="scale("+scale+")"},resize=function(){iv&&clearTimeout(iv),iv=setTimeout(winZoom,300)}
each(vendors,function(vendor,evt){return testEl.style[vendor+"TransitionProperty"]!==void 0?(prefix=vendor,!1):void 0}),window.onresize=resize,winZoom()})(900,500,30,30)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<title>Document</title>
<style type="text/css">
html,body{
height: 100%;
width: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
body{
padding-top: 1px;
overflow: hidden;
}
.container{
width: 900px;
height: 500px;
background-color: hsl(60,20%,80%);
margin: 0 auto;
-webkit-transition: all 400ms;
-moz-transition: all 400ms;
-ms-transition: all 400ms;
-o-transition: all 400ms;
transition: all 400ms;
}
</style>
</head>
<body>
<div class="container"></div>
<script type="text/javascript" src="fix_zoom.min.js"></script>
</body>
</html>
@Mrshcom
Copy link

Mrshcom commented Jun 27, 2013

to IE2 ham kar nemikone! :))

@omidgharib
Copy link

to netscape 5.5 kar mikone vali :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment