rem简单实现移动端适配
来源:互联网 发布:德国 四川 知乎 编辑:程序博客网 时间:2024/06/06 11:05
rem:移动web开发
默认字体大小是16px
在
<html>
中设置字体大小与em的区别:
- em是在父级设置字体大小受影响
移动端适配
首先获取屏幕的宽度
计算当前屏幕宽度和640的比例
计算出font-size的值
改变html的font-size的值
<!DOCTYPE html><html lang="en" style="font-size: 100px;"><head> <meta charset="UTF-8"> <title>rem</title> <style> * { margin: 0; padding: 0; } div { width: 6.4rem; height: 6.4rem; background-color: pink; font-size: .14rem; margin: 0 auto; } p { width: 50%; height: 50%; background-color: skyblue; } </style></head><body> <div> <p>这是一个p</p> </div></body></html>
第一种:
window.onresize = function(){ var html = document.getElementsByTagName('html')[0]; var width = html.offsetWidth; console.log(width); html.style.fontSize = (width>=640?640:width)/640*100 + 'px';};
第二种:
var html = document.getElementsByTagName('html')[0]; if(html){ var w = window.innerWidth; var fontSize = (w>640?640:w)/640 * 100; html.style.fontSize = fontSize + 'px'; } window.onload = function(){ window.onresize = function(){ var w = window.innerWidth; console.log(w); var fontSize = (w>640?640:w)/640 * 100; html.style.fontSize = fontSize + 'px'; } }
https://github.com/PaddyWang/summarize
0 0
- rem简单实现移动端适配
- 移动端适配之rem
- 移动端适配rem
- rem灵活移动端适配
- js动态计算移动端rem(移动端适配rem)
- 简单的移动端rem布局方法
- HTML5实现移动端之-rem布局
- 移动端用rem的实现
- 移动端适配——rem方案
- rem,移动端适配心得2【转载】
- js 移动端适配 (动态rem)
- rem与media标签实现移动端屏幕适配
- 移动端自适应rem
- 移动端rem布局
- 移动布局之rem
- 移动端 rem
- 移动端rem设置
- 移动端 单位 rem
- 数理逻辑(7 0 0) 直接证明与演绎
- Reconstruct Itinerary
- telnet的使用[简单的使用 其他的另外百度]
- BestCoder Round #77 (div.2)(A)
- MySQL性能优化配置诀窍之细水长流
- rem简单实现移动端适配
- LayoutInflater.inflate详解
- 如何交换两个数的值?中间变量法,加减运算法,位运算法
- BestCoder Round #77 (div.2)(B)数学
- Spring Batch(7): 并行与扩展
- HDU_ACM_A+B for Input-Output Practice (III)
- 递归的故事
- UIViewController的生命周期及iOS程序执行顺序
- 杭电2544最短路