移动适配的几种方案(三种方案)
2017-08-11 23:54
225 查看
1.直接利用js适配
例如:100px=1rem;10px=0.1rem;1px=0.01rem;
2.利用js+less适配
less:文件顶部定义@unit: 750/10rem,然后css全文件的单位直接用@unit。
例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;
3.利用less适配。
例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;
参考原文链接:https://zhuanlan.zhihu.com/p/23837333?refer=dreawer
(function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window);
例如:100px=1rem;10px=0.1rem;1px=0.01rem;
2.利用js+less适配
(function (win) { function setUnitA() { document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px"; } var h = null; window.addEventListener("resize", function () { clearTimeout(h); h = setTimeout(setUnitA, 300); }, false); setUnitA(); })(window);
less:文件顶部定义@unit: 750/10rem,然后css全文件的单位直接用@unit。
例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;
3.利用less适配。
html { font-size: 20px; } @media only screen and (min-width: 401px) { html { font-size: 25px !i 4000 mportant; } } @media only screen and (min-width: 428px) { html { font-size: 26.75px !important; } } @media only screen and (min-width: 481px) { html { font-size: 30px !important; } } @media only screen and (min-width: 569px) { html { font-size: 35px !important; } } @media only screen and (min-width: 641px) { html { font-size: 40px !important; } } @unit: 40rem;
例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;
参考原文链接:https://zhuanlan.zhihu.com/p/23837333?refer=dreawer
相关文章推荐
- 移动适配的几种方案(三种方案)
- 移动webapp页面适配方案
- 几种移动app API调用认证方案浅析
- 移动webapp页面适配方案
- 百度开放适配服务三种方案:自主适配、标注Meta声明、提交对应关系sitemap
- 移动适配请使用比rem等更好的布局方案
- 解惑好文:移动端H5页面高清多屏适配方案
- 移动webapp页面适配方案
- android 启动广告 适配几种方案
- 移动适配方案的总结
- 移动端 移动web屏幕适配方案 随不同宽度的屏幕而改变
- WF4实现工作流驳回流转模型的几种设计方案
- JSP避免Form重复提交的三种方案
- 一道matlab作业题:假设从楼上到楼下有8个台阶,每一步有三种走法:走1个台阶;走2个台阶;走3个台阶,问可以有多少种方案?并将所有方案输出
- java的list几种实现方式的效率(ArrayList、LinkedList、Vector、Stack),以及 java时间戳的三种获取方式比较
- 《黄聪:手机移动站SEO优化教程》4、如何实现手机移动网站和PC站点的自主适配
- Css3 Media Queries移动页面的样式和图片的适配问题(转)
- 移动APP整体策划-004-App注册登录系统策划方案
- 提升移动应用体验的三种方法
- node解决异步问题三种方案