您的位置:首页 > 移动开发

手机移动端web资源整合

2017-10-21 21:51 453 查看
做移动端开发,会存在各种兼容问题。

meta基础知识

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maxinum-scale=1.0,user-scalable=no"


忽略将页面中的数字识别为电话号码

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


忽略Android平台中对邮箱地址的识别

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


当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅针对ios的safari

<meta name="app-mobile-web-app-capable" content="yes"/>
<!-- ios7.0版本以后,safari上已看不到效果-->


将网站添加到主屏幕快速启动方式,仅针对ios的safari顶端状态条的样式

<meta name="app-mobile-web-app-status-bar-style" content="black"/>
<!--可选default、black、black-translucent-->


viewport模板

viewport模板——通用

<!DOCTYPE html>
<html>
4000
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>标题</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
这里开始内容
</body>
</html>


viewport模板——target-densitydpi=device-api,android2.3.5以下版本不支持

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=750, user-scalable=no, target-densitydpi=device-dpi"><!-- width取值与页面定义的宽度一致 -->
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>标题</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
这里开始内容
</body>
</html>


常见问题

移动端如何定义字体font-family

中文字体使用系统默认即可,英文用Helvetica

/* 移动端定义字体的代码 */
body{font-family:Helvetica;}


参考《移动端使用字体的思考》

移动端字体单位font-size选择px还是rem

对于只需要适配少部分手机设备,且分辨率对页面影响不大,使用px即可

对于需要适配各种移动设备,使用rem,例如只需要适配iPhone和iPad等分辨率差别比较大的设备

rem配置参考:

html{font-size:10px}
@media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}}
@media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}}
@media screen and (min-width:415px) and (max-width:639px){html{font-size:15px}}
@media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}}
@media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}}
@media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}}
@media screen and (min-width:800px){html{font-size:25px}}


移动端touch事件(区分webkit和winphone)

当用户手指放在移动设备在屏幕上滑动会触发touch事件

以下支持webkit

touchstart——当手指碰触屏幕时候发生。不管当前有多少手指

touchmove——当手指真正在屏幕上滑动时连续触发。通常我们再滑屏页面,会调用event的preventDefault可以阻止默认情况的发生;阻止页面滚动

touchend——当手指离开屏幕时触发

touchcancel——系统停止跟踪触摸时候会触发。例如在触摸过程中突然页面alert()一个提示框,此时会触发该事件,这个事件比较少用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: