h5布局之道(最终篇)
大家好,时隔一年多了,前几篇探讨的rem布局后来又有改进不过一直没有想起来更新博客,rem布局淘宝用的也比较早,有兴趣的可以看看淘宝的flexible
,我的用法比较简单,原来一样,废话不说了直接上代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <!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> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!