移动端开发注意问题

1、防止手机中网页放大和缩小,这点是最基本的,最为手机网站开发者来说应该都知道的,就是设置meta中的viewport

使用viewport使页面禁止缩放。 通常把user-scalable设置为0来关闭用户对页面视图缩放的行为。

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

 

2、苹果手机的一些设置。

<meta name="apple-mobile-web-app-capable" content="yes">

如果content设置为yes,Web应用会以全屏模式运行,反之,则不会。content的默认值是no,表示正常显示。你可以通过只读属性window.navigator.standalone来确定网页是否以全屏模式显示。

 

3、format-detection设置。★

<meta name="format-detection" content="telephone=no"><meta name="format-detection" content="email=no">

format-detection 启动或禁用自动识别页面中的电话号码、邮箱地址。

1.标准的电话号码格式是这样的:<a  href="tel:1-408-555-5555">1-408-555-5555</a>,点击后会自动打开电话功能;

 

4、上下拉动滚动条时卡顿、慢 ★

body { -webkit-overflow-scrolling: touch; //苹果手机 overflow-scrolling: touch;}

 

5、禁止复制、选中文本

* {

-webkit-touch-callout: none;

-webkit-user-select: none;

-khtml-user-select: none;

-moz-user-select: none;

-ms-user-select: none;

user-select: none;

}

 

6、长时间按住页面出现闪退 ★

element { -webkit-touch-callout: none;}

 

7、iphone及ipad下输入框默认内阴影★★★

Element{ -webkit-appearance: none; }

 

8、ios和android下触摸元素时出现半透明灰色遮罩 ★★★

Element { -webkit-tap-highlight-color:rgba(255,255,255,0)}

 

8.1、苹果输入框点击不放大 ★★★

<meta content="yes" name="apple-mobile-web-app-capable">

<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">

 

 

9、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>

 

10、动画定义3D启用硬件加速

Element { -webkit-transform:translate3d(0, 0, 0) transform: translate3d(0, 0, 0);}

注意:3D变形会消耗更多的内存与功耗

 

11、Retina屏的1px边框

Element{ border-width: thin;}

 

12、旋转屏幕时,字体大小调整的问题

*{ -webkit-text-size-adjust:100%; }

 

13、顶部状态栏背景色

<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 +

 

14、设置缓存

<meta http-equiv="Cache-Control" content="no-cache" />

手机页面通常在第一次加载后会进行缓存,然后每次刷新会使用缓存而不是去重新向服务器发送请求。如果不希望使用缓存可以设置no-cache。

 

15、桌面图标

<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" />

 

16、浏览器私有及其它meta

全屏模式

<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">

 

 

17、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>

 

18、被点击元素的外观变化,可以使用样式来设定

-webkit-tap-highlight-color: 颜色

 

19、判断软键盘弹出

android上,当软键盘状态改变的时候,会触发window的resize事件,所以我们可以进入页面的时候保存一次window.innerHeight的值,当window的resize事件触发的时候,比较window.innerHeight的值与前一次保存的window.innerHeight的值大小来判断软键盘的收拢和弹出状态。

 

var winHeight = window.innerHeight; if (isAndroid) { window.addEventListener('resize', function(e) { var tempHeight = window.innerHeight if (tempHeight < winHeight) { bShowRec = false; } else { bShowRec = true; } }); }

 

ios上,软键盘状态改变的时候,不会触发window的resize事件,但是当软键盘的“完成”按钮被点击的时候,会触发onblur事件。所以正常通过onfocus和onblur事件来判断就行。

 

20、阻止旋转屏幕时自动调整字体大小

html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6 {-webkit-text-size-adjust:none;}

 

21、禁止body滚动

document.body.ontouchmove=function(e){ e.preventDefault(); }

 

22.拍照上传

<input type=file accept="video/*"><input type=file accept="image/*">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值