1.像素

设计图要按分辨率来做,分为640,720,1080等等像素的。

下边来引入逻辑像素概念:

苹果5的逻辑像素是:320*568

苹果6的逻辑像素是:375*667

苹果6+的逻辑像素是:414*736

安卓的逻辑像素有很多,我们可以按照320*533和360*640来计算

接下来我们就要来说一下倍率:

假如设计师设计的是640像素的图,那我们以苹果5为标准来做设计,苹果5的逻辑像素是320,那么做设计的时候,就要将图纸的单位都缩小一半,才能让苹果5的显示情况和图的效果达到一致。以此类推,如果给的图纸是720的,那么就要缩放2.25倍才能达到一致!!

2.触摸事件

2.1、Touch事件简介

pc上的web页面鼠 标会产生onmousedown、onmouseup、onmouseout、onmouseover、onmousemove的事件,但是在移动终端如 iphone、ipod Touch、ipad上的web页面触屏时会产生ontouchstart、ontouchmove、ontouchend、ontouchcancel 事件,分别对应了触屏开始、拖拽及完成触屏事件和取消。
当按下手指时,触发ontouchstart;
当移动手指时,触发ontouchmove;
当移走手指时,触发ontouchend。
当一些更高级别的事件发生的时候(如电话接入或者弹出信息)会取消当前的touch操作,即触发ontouchcancel。一般会在ontouchcancel时暂停游戏、存档等操作。

2.2、Touch事件与Mouse事件的出发关系

在触屏操作后,手指提起的一刹那(即发生ontouchend后),系统会判断接收到事件的element的内容是否被改变,如果内容被改变,接下来的事 件都不会触发,如果没有改变,会按照mousedown,mouseup,click的顺序触发事件。特别需要提到的是,只有再触发一个触屏事件时,才会 触发上一个事件的mouseout事件。

2.3、gesture事件

Gesture事件,包括手指点击(click),轻拂 (flick),双击(double-click),手指的分开、闭合(scale)、转动(rotate)等一切手指能在屏幕上做的事情,它只在有两根 或多根手指放在屏幕上的时候触发,事件处理函数中会得到一个GestureEvent类型的参数,它包含了手指的scale(两根移动过程中分开的比例) 信息和rotation(两根手指间连线转动的角度)信息。这个事件是对touch事件的更高层的封装,和touch一样,它同样包括 gesturestart,gesturechange,gestureend。
gesture事件触发过程:
Step 1、第一根手指放下,触发touchstart
Step 2、第二根手指放下,触发gesturestart
Step 3、触发第二根手指的touchstart
Step 4、立即触发gesturechange
Step 5、手指移动,持续触发gesturechange,就像鼠标在屏幕上移动的时候不停触发mousemove一样
Step 6、第二根手指提起,触发gestureend,以后将不会再触发gesturechange
Step 7、触发第二根手指的touchend
Step 8、触发touchstart!注意,多根手指在屏幕上,提起一根,会刷新一次全局touch!重新触发第一根手指的touchstart
Step 9、提起第一根手指,触发touchend

关键字说明:

clientX:触摸目标在视口中的X坐标。
clientY:触摸目标在视口中的Y坐标。
identifier:表示触摸的唯一ID。
pageX:触摸目标在页面中的x坐标。
pageY:触摸目标在页面中的y坐标。
screenX:触摸目标在屏幕中的x坐标。
screenY:触摸目标在屏幕中的y坐标。
target:触摸的DOM节点坐标。

3.meta标签

1.关闭识别手机号

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

2.关闭识别后,想识别个别的电话

1
<a href="tel:13800138000">13800138000</a>

3.关闭邮箱识别

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

4.苹果顶部工具栏样式

1
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明)。
注意: 若值为”black-translucent”将会占据页面px位置,浮在页面上方(会覆盖页面20px高度–iphone4和itouch4的Retina屏幕为40px) 在用户把网页存为书签时,在手机HOME界面创建应用程序样式的图标

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

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

6.苹果的favicon图标设置

1
2
<link rel="apple-touch-icon" href="/static/images/identity/HTML5_Badge_64.png" /> 
<link rel="apple-touch-icon-precomposed" href="/static/images/identity/HTML5_Badge_64.png" />

iOS用rel=”apple-touch-icon”
android 用rel=”apple-touch-icon-precomposed”

7.DNS 预解析技术:
只有在访问过一次后才会缓存DNS解析
就是说首次进入页面,是无法预解析的

方法一

1
<link rel="dns-prefetch" href="//img.58cdn.com.cn">

方法二

1
<meta http-equiv="x-dns-prefetch-control" content="on">

8、移动端页面设置视口宽度等于设备宽度,并禁止缩放。

1
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

9、移动端页面设置视口宽度等于定宽(如640px),并禁止缩放,常用于微信浏览器页面。

1
<meta name="viewport" content="width=640,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

10、增加到windows的图标样式

1
2
<meta name="msapplication-TileImage" content="/static/img/icons/msapplication-icon-144x144.png">
<meta name="msapplication-TileColor" content="#000000">

viewport模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<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">
<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="//j2.58cdn.com.cn">
<title>title</title>
<link rel="stylesheet" href="index.css">
</head>

<body>
content...
</body>

</html>

4. CSS样式技巧

1、禁止ios和android用户选中文字

1
.css{-webkit-user-select:none}

2、禁止ios长按时触发系统的菜单,禁止ios&android长按时下载图片

1
.css{-webkit-touch-callout: none}

3、webkit去除表单元素的默认样式

1
.css{-webkit-appearance:none;}

4、修改webkit表单输入框placeholder的样式

1
2
input::-webkit-input-placeholder{color:#AAAAAA;}
input:focus::-webkit-input-placeholder{color:#EEEEEE;}

5、去除android a/button/input标签被点击时产生的边框 & 去除ios a标签被点击时产生的半透明灰色背景

1
a,button,input{-webkit-tap-highlight-color:rgba(255,0,0,0);}

6、ios使用-webkit-text-size-adjust禁止调整字体大小

1
body{-webkit-text-size-adjust: 100%!important;}

7、android 上去掉语音输入按钮

1
input::-webkit-input-speech-button {display: none}

8、移动端定义字体,移动端没有微软雅黑字体
/ 移动端定义字体的代码 /

1
body{font-family:Helvetica;}

5. 其他技巧

1、手机拍照和上传图片

1
2
3
4
<!-- 选择照片 -->
<input type=file accept="image/*">
<!-- 选择视频 -->
<input type=file accept="video/*">

2、取消input在ios下,输入的时候英文首字母的默认大写

1
<input autocapitalize="off" autocorrect="off" />

3、打电话和发短信

1
2
<a href="tel:0755-10086">打电话给:0755-10086</a>
<a href="sms:10086">发短信给: 10086</a>

6. CSS reset

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* hcysun  */
@charset "utf-8";
/* reset */
html{
-webkit-text-size-adjust:none;
-webkit-user-select:none;
-webkit-touch-callout: none
font-family: Helvetica;
}
body{font-size:12px;}
body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0; padding:0; font-weight: normal;text-indent: 0;}
a,button,input,textarea,select{ background: none; -webkit-tap-highlight-color:rgba(255,0,0,0); outline:none; -webkit-appearance:none;}
em{font-style:normal}
li{list-style:none}
a{text-decoration:none;}
img{border:none; vertical-align:top;}
table{border-collapse:collapse;}
textarea{ resize:none; overflow:auto;}
/* end reset */

7. flex布局 兼容写法

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
1、定义弹性盒模型兼容写法
/*
box
inline-box
*/
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -o-box;
display: box;
2、box-orient 定义盒模型内伸缩项目的布局方向
/**
* vertical column 垂直
* horizontal row 水平 默认值
*/
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-ms-flex-direction: row;
-o-box-orient: horizontal;
box-orient: horizontal;
3、box-direction 定义盒模型内伸缩项目的正序(normal默认值)、倒叙(reverse)
/* Firefox */
display:-moz-box;
-moz-box-direction:reverse;
/* Safari、Opera 以及 Chrome */
display:-webkit-box;
-webkit-box-direction:reverse;
4、box-pack 对盒子水平富裕空间的管理
/*
start
end
center
justify
*/
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-o-box-pack: center;
box-pack: center;
5、box-pack 对盒子垂直方向富裕空间的管理
/*
start
end
center
*/
/* box-align */
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-o-box-align: center;
box-align: center;
6、定义伸缩项目的具体位置
/*-moz-box-ordinal-group:1;*/ /* Firefox */
/*-webkit-box-ordinal-group:1;*/ /* Safari 和 Chrome */
.box div:nth-of-type(1){-webkit-box-ordinal-group:1;}
.box div:nth-of-type(2){-webkit-box-ordinal-group:2;}
.box div:nth-of-type(3){-webkit-box-ordinal-group:3;}
.box div:nth-of-type(4){-webkit-box-ordinal-group:4;}
.box div:nth-of-type(5){-webkit-box-ordinal-group:5;}
7、定义伸缩项目占空间的份数
-moz-box-flex:2.0; /* Firefox */
-webkit-box-flex:2.0; /* Safari 和 Chrome */

.box div:nth-of-type(1){-webkit-box-flex:1;}
.box div:nth-of-type(2){-webkit-box-flex:2;}
.box div:nth-of-type(3){-webkit-box-flex:3;}
.box div:nth-of-type(4){-webkit-box-flex:4;}
.box div:nth-of-type(5){-webkit-box-flex:5;}
← Prev Next →