h5布局之道(最终篇)
2016-04-28 15:19
507 查看
大家好,时隔一年多了,前几篇探讨的rem布局后来又有改进不过一直没有想起来更新博客,rem布局淘宝用的也比较早,有兴趣的可以看看淘宝的flexible
,我的用法比较简单,原来一样,废话不说了直接上代码
,我的用法比较简单,原来一样,废话不说了直接上代码
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no"/> <title>GreatBoy</title> <style> /*-----css Reset end-----*/ body,h1,h2,h3,h4,h5,h6,p,ul,ol,form{ margin:0; padding:0px; } html{ /* display: none;*/ } body{ font-size: 14px; } .nav img{ width: 100%; } </style> </head> <body> <div class="nav"><img src="http://p1.jmstatic.com/banner/75/mobile_app/24326_0.jpg"/></div> <div id="container"> <div id="user">用户信息<span id="userinfo"></span></div> </div> <script> (function(win) { var doc = win.document, scale = 16, $body = doc.getElementsByTagName('body')[0], $html = doc.getElementsByTagName('html')[0], windowWidth = doc.documentElement && doc.documentElement.clientWidth || doc.body.clientWidth || win.innerWidth, windowHeight = document.documentElement && document.documentElement.clientHeight || documentElement.body.clientHeight || window.innerHeight, deviceAgent = navigator.userAgent.toLowerCase(); if ( deviceAgent.match( /(iphone|ipod|ipad|android|windows\s*phone|symbianos)/ ) ) { try{ // if ( window.localStorage && window.localStorage.getItem('scale_greatboy') ) { // scale = window.localStorage.getItem('scale_greatboy'); // } else { scale = parseFloat(windowWidth * 16 / (16*3.2)); if (windowHeight > windowWidth) { //window.localStorage && window.localStorage.setItem('scale_greatboy', scale); } // } }catch(e){ } if (deviceAgent.match(/android\s*2.3/) && deviceAgent.match(/micromessenger/)) { scale = 16; } $html.style.fontSize = scale + 'px'; $html.style.display = 'block'; } else { window.onresize = function(){ windowWidth = doc.documentElement && doc.documentElement.clientWidth || doc.body.clientWidth || win.innerWidth; scale = parseFloat(windowWidth * 16 / (16*3.2)); $html.style.fontSize = scale + 'px'; }; scale = parseFloat(windowWidth * 16 / (16*3.2)); $html.style.fontSize = scale + 'px'; $html.style.display = 'block'; } $body.style.width = '3.2rem'; })(window); </script> </body> </html>
相关文章推荐
- html5 离线存储 worker
- Html5
- H5元素
- Html5标签页面
- HTML5触摸事件(多点触控、单点触控)Demo
- 微软的基于webgl的H5 3D游戏引擎
- 8. H5 pushState/popstate + ajax开发无刷新页面
- 开大你的音响,感受HTML5 Audio API带来的视听盛宴
- PS雪碧图快捷键
- HTML5-01 简介
- HTML5:烟火
- html5开发之viewport使用
- HTML5翻页电子书
- html5-注意的细节
- html5-html基础
- CDH5使用安装报错解决办法
- HTML5——同步购物车
- h5学习笔记:line-height和height组合居中
- 超炫的HTML5粒子效果进度条 VS 如何规范而优雅地code
- Html5实现自己的分页加载