Html5前端笔记

获取Dpi

在 window.load中添加:

(function(){
 	if (!window.screen.deviceXDPI){
       var tmpNode = document.createElement("DIV");
        tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
        document.body.appendChild(tmpNode);
        window.screen.deviceXDPI = parseInt(tmpNode.offsetWidth);
        window.screen.deviceYDPI = parseInt(tmpNode.offsetHeight);
        tmpNode.parentNode.removeChild(tmpNode);
 	}

    //宽度毫米
    window.screen.width_mm =  window.screen.width / window.screen.deviceXDPI * 25.4;
    window.screen.height_mm =  window.screen.height / window.screen.deviceYDPI * 25.4;
})()

可以根据 屏幕的真实宽度与高度进行适配.

一些链接

http://blog.csdn.net/cuixiping/article/details/45966177
https://www.pengxb.com/
http://yincheng.site/crop-upload-photo

posted @ 2017-10-26 14:59  NewSea  阅读(210)  评论(0编辑  收藏  举报