一、使用viewport使页面禁止缩放。 一般把user-scalable设置为0来关闭用户对页面视图缩放的行为。javascript
完整的viewport设置,固然,user-scalable=0,有的人也写成user-scalable=no,均可以的。html
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
二、苹果手机的一些设置。html5
<meta name="apple-mobile-web-app-capable" content="yes">
若是content设置为yes,Web应用会以全屏模式运行,反之,则不会。content的默认值是no,表示正常显示。你能够经过只读属性window.navigator.standalone来肯定网页是否以全屏模式显示。java
三、format-detection设置。android
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="email=no">
format-detection 启动或禁用自动识别页面中的电话号码、邮箱地址。ios
四、上下拉动滚动条时卡顿、慢web
body { -webkit-overflow-scrolling: touch; overflow-scrolling: touch; }
Android3+和iOS5+支持CSS3的新属性为overflow-scrollingajax
五、禁止复制、选中文本windows
Element { -webkit-user-select: none; -moz-user-select: none; -khtml-user-select: none; user-select: none; }
解决移动设备可选中页面文本(视产品须要而定)浏览器
六、长时间按住页面出现闪退
element { -webkit-touch-callout: none; }
七、iphone及ipad下输入框默认内阴影
Element{ -webkit-appearance: none; }
八、ios和android下触摸元素时出现半透明灰色遮罩
Element { -webkit-tap-highlight-color:rgba(255,255,255,0) }
九、active兼容处理 即 伪类 :active 失效
方法一:body添加ontouchstart
<body ontouchstart="">
方法二:js给 document 绑定 touchstart 或 touchend 事件
<style> a { color: #000; } a:active { color: #fff; } </style> <a herf=foo >bar</a> <script> document.addEventListener(‘touchstart‘,function(){},false); </script>
十、动画定义3D启用硬件加速
Element { -webkit-transform:translate3d(0, 0, 0) transform: translate3d(0, 0, 0); }
注意:3D变形会消耗更多的内存与功耗
十一、Retina屏的1px边框
Element{ border-width: thin; }
十二、旋转屏幕时,字体大小调整的问题
*{ -webkit-text-size-adjust:100%; }
1三、顶部状态栏背景色
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
说明:
除非你先使用apple-mobile-web-app-capable指定全屏模式,不然这个meta标签不会起任何做用。
若是content设置为default,则状态栏正常显示。若是设置为blank,则状态栏会有一个黑色的背景。若是设置为blank-translucent,则状态栏显示为黑色半透明。若是设置为default或blank,则页面显示在状态栏的下方,即状态栏占据上方部分,页面占据下方部分,两者没有遮挡对方或被遮挡。若是设置为blank-translucent,则页面会充满屏幕,其中页面顶部会被状态栏遮盖住(会覆盖页面20px高度,而iphone4和itouch4的Retina屏幕为40px)。默认值是default。
兼容性 iOS 2.1 +
1四、设置缓存
<meta http-equiv="Cache-Control" content="no-cache" />
手机页面一般在第一次加载后会进行缓存,而后每次刷新会使用缓存而不是去从新向服务器发送请求。若是不但愿使用缓存能够设置no-cache。
1五、桌面图标
<link rel="apple-touch-icon" href="touch-icon-iphone.png" /> <link rel="apple-touch-icon" sizes="76x76" href="touch-icon-ipad.png" /> <link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png" /> <link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png" />
1六、浏览器私有及其它meta
QQ浏览器私有
全屏模式
<meta name="x5-fullscreen" content="true">
强制竖屏
<meta name="x5-orientation" content="portrait">
强制横屏
<meta name="x5-orientation" content="landscape">
应用模式
<meta name="x5-page-mode" content="app">
UC浏览器私有
全屏模式
<meta name="full-screen" content="yes">
强制竖屏
<meta name="screen-orientation" content="portrait">
强制横屏
<meta name="screen-orientation" content="landscape">
应用模式
<meta name="browsermode" content="application">
其它
针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,好比黑莓
<meta name="HandheldFriendly" content="true">
微软的老式浏览器
<meta name="MobileOptimized" content="320">
windows phone 点击无高光
<meta name="msapplication-tap-highlight" content="no">
1七、IOS中input键盘事件keyup、keydown、keypress支持不是很好
问题是这样的,用input search作模糊搜索的时候,在键盘里面输入关键词,会经过ajax后台查询,而后返回数据,而后再对返回的数据进行关键词标红。用input监听键盘keyup事件,在安卓手机浏览器中是能够的,可是在ios手机浏览器中变红很慢,用输入法输入以后,并未马上相应keyup事件,只有在经过删除以后才能相应!
解决方法:能够用html5的oninput事件去代替keyup
<input type="text" id="testInput"> <script type="text/javascript"> document.getElementById(‘testInput‘).addEventListener(‘input‘, function(e){ var value = e.target.value; }); </script>