手机端开发笔记-迭代记录

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

有些手机网站我们看到如下声明:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

设置了DTD的方式是XHTML的写法,假如我们页面运用的是 html5,可以不用设置DTD,直接声明 <!DOCTYPE html>。

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

完整的viewport设置,当然,user-scalable=0,有的人也写成user-scalable=no,都可以的。

<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 启动或禁用自动识别页面中的电话号码、邮箱地址。

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

body {
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}

Android3+和iOS5+支持CSS3的新属性为overflow-scrolling

5、禁止复制、选中文本

Element {
-webkit-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
user-select: none;
}

*:not(input,textarea){
-moz-user-select: none;
-o-user-select:none;
-khtml-user-select:none;
-webkit-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)
}

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

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

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‘ 手机上显示蓝色的数字(7位数;苹果手机会默认为电话号码;可以点击拨打;后台请求的日期也是蓝色) 解决:

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

19 微信滚动条苹果手机上滚动不顺畅 加上以下属性就可以了;
-webkit-overflow-scrolling : touch;

20.
/*a链接点击图片出现闪一下*/
html{-webkit-tap-highlight-color:none}
html{-webkit-tap-highlight-color:transparent;}

时间: 2024-07-29 18:30:14

手机端开发笔记-迭代记录的相关文章

手机端开发

meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 <meta name="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=&

RAP开发入门-开发笔记-bug记录

NamespaceException: The alias '/rwt-resources' is already in use 该bug发生的第一种情况是: This means that more than one application is started in the same context and in the same HttpService. When different applications run in the same HttpService, they have t

H5手机端开发问题及解决方案

ios竖屏拍照上传,图片被旋转问题 1.通过第三方插件exif-js获取到图片的方向2.new一个FileReader对象,加载读取上传的图片3.在fileReader的onload函数中,得到的图片文件用一个Image对象接收4.在image的onload函数中,利用步骤1中获取到的方向orientation,通过canvas旋转校正,重新绘制一张新图注意iPhone有3个拍照方向需要处理,横屏拍摄,home键在左侧,竖屏拍摄,home建上下5.将绘制的新图转成Blob对象,添加到FormDa

[共通]手机端网页开发问题及解决方法整理

Q1:手机端开发网页,界面适应问题.A1: <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> width - viewport的宽度 height - viewport的高度    initial-scale - 初始的缩放比例    minimum-scale - 允许用户缩放到的最小比

专注手机端前端界面开发的ui组件和js组合

frozenui一款腾讯开发的简化版Bootstrap,只用于手机端 http://frozenui.github.io/ https://github.com/frozenui/frozenui zepto.js专注于手机端开发的js库 http://www.zeptojs.cn/            官方文档 http://www.css88.com/doc/zeptojs/         在线文档

网页开发笔记【一】创建一个半透明的页面

近来正在温习网页制作,系列<网页开发笔记>记录本人在解决网页开发过程中遇到的问题以及解决方案. 半透明的页面在网页开发中使用的比较广泛,尤其在web app中,这种设计使用的地方更为广泛,本文记录这种半透明的页面的开发方法. 半透明页面常用于用户注册,这时候弹出一个页面能在不离开当前页面的情况下完成注册. 如百度的登陆界面所示. 我的处理方法如下: 首先在页面写一个div,这个div平时display设置为none,当需要的时候设置为display:block; 这个div(设其id为popu

手机端微信聊天记录数据库解密过程记录

出发点是想找回微信被撤回的信息. 根据<PC版QQ微信防撤回补丁>文章,拦截PC端的撤回函数,新的撤回消息将不会被撤回.但是打补丁前撤回的消息,依然无法查看. 之前发现,手机端的微信,图片.视频信息撤回后,可以在本地找到相应的记录.由此猜测,文本信息是否本地依然有记录.查询资料得知,文本的聊天记录,存放在Sqlite数据库中.本来想破解PC端的数据库,但是收集到的资料都是手机端的. 根据<手把手教你破解微信本地数据库(利用Sqlcipher查看)>和<Android动态破解微

手机端网页web开发要点

1.初始化 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,u

JS前端开发判断是否是手机端并跳转操作(小结)

JS前端开发判断是否是手机端并跳转操作(小结) 这篇文章主要介绍了JS前端开发判断是否是手机端并跳转操作,非常不错,具有参考借鉴价值,需要的朋友可以参考下 常用跳转代码 ? 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 <script type="text/javascript">  // borwserR