Skip to content

Instantly share code, notes, and snippets.

@daqi
Last active April 20, 2016 03:53
Show Gist options
  • Save daqi/2ad65de89cb5560eb717b12dd75755e4 to your computer and use it in GitHub Desktop.
Save daqi/2ad65de89cb5560eb717b12dd75755e4 to your computer and use it in GitHub Desktop.
var trys = 0;
function pageInit(){
var imgW = 695,
imgH = 1033,
wW = window.innerWidth,
wH = window.innerHeight,
_imgW, _imgH,
picbg = document.getElementById('picbg'),
px2rem = function(px){
return px/(imgW/10);
};
if (imgW/imgH > wW/wH) {
_imgW = wW;
_imgH = imgH/imgW * wW;
document.documentElement.style.fontSize = _imgW/10+'px';
}else{
_imgH = wH;
_imgW = imgW/imgH * wH;
document.documentElement.style.fontSize = _imgW/10+'px';
}
picbg.style.width = px2rem(imgW) + 'rem';
picbg.style.height = px2rem(imgH) + 'rem';
if (wW/wH>1.1 && trys<100) {
setTimeout(function(){
trys++;
pageInit();
},10)
}
}
window.onload = function(){
pageInit();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment