forked from junmer/mobile-dev-get-started
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
559 lines (461 loc) · 16.9 KB
/
index.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reveal.js</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
</head>
<body>
<div class="reveal">
<div class="slides"><section data-markdown><script type="text/template"># 移动web开发入门
</script></section><section data-markdown><script type="text/template">
# 目标
* 建立基本的移动web开发知识体系
* 常见问题的实践
</script></section><section data-markdown><script type="text/template">
# 内容
* 基本概念
* 视觉
* 交互
* 实践
* 调试
</script></section><section ><section data-markdown><script type="text/template">
# 基本概念
</script></section><section data-markdown><script type="text/template">
### native
> 本地应用
> 使用 `Java` \ `Objective-C` \ `Swift` 开发
</script></section><section data-markdown><script type="text/template">
### webapp
> 网页应用
> `html5` 开发
</script></section><section data-markdown><script type="text/template">
### hybrid
> 混合应用
> ooxx(native, web)
</script></section><section data-markdown><script type="text/template">
### 对比
| | Web App | Hybrid App | Native App |
|:---------------- |:----------------:|:----------:|:-----------:|
| 开发成本 | 低 | 中 | 高 |
| 维护更新 | 简单 | 简单 | 复杂 |
| 体验 | 差 | 中 | 优 |
| Store/market认可 | 不认可(轻应用?)| 认可 | 认可 |
| 安装 | 不需要 | 需要 | 需要 |
| 跨平台 | 优 | 优 | 差 |
</script></section></section><section ><section data-markdown><script type="text/template">
# 视觉
</script></section><section data-markdown><script type="text/template">
### devicePiexelRatio
> `pixel` - px ( picture element )
> `dpi` / `ppi` - 每英寸像素 ( dot per inch )
> `dips` - 设备独立像素 ( device-independent pixels )
> `devicePixelRatio` - 物理像素 / dips
</script></section><section data-markdown><script type="text/template">
![devicePiexelRatio](./img/devicePiexelRatio.jpg)
</script></section><section data-markdown><script type="text/template">
### 文字 px, rem
> 固定大小 - px
> 多屏适配,统一修改 - rem
> rem - font size of the root element [(W3C)](http://www.w3.org/TR/css3-values/#rem-unit)
> Q: why not em? A: r
</script></section><section data-markdown><script type="text/template">
### viewport
```
<meta name="viewport"
content="width=device-width,
height=device-height,
inital-scale=1.0,
maximum-scale=1.0,
user-scalable=no;"
/>
```
> `width` - viewport的宽度
> `height` - viewport的高度
> `initial-scale` - 初始的缩放比例
> `maximum-scale` - 允许用户缩放到的最大比例
> `user-scalable` - 用户是否可以手动缩放
</script></section><section data-markdown><script type="text/template">
### 橫屏/竖屏
```
window.addEventListener('orientationchange', function() {
// rerender something
});
console.log(window.orientation); // 0, 90, 180, -90 顺时针角度
```
```
<style media="all and (orientation:portrait)" type="text/css">
/* 竖屏 */
</style>
<style media="all and (orientation:landscape)" type="text/css">
/* 横屏 */
</style>
```
> [matchMedia](https://github.com/ecomfe/saber-matchmedia)
</script></section><section data-markdown><script type="text/template">
### flex 伸缩布局
```
.container {
display: -webkit-flex;
display: flex;
}
.initial {
-webkit-flex: initial;
flex: initial;
width: 200px;
min-width: 100px;
}
.none {
-webkit-flex: none;
flex: none;
width: 200px;
}
.flex1 {
-webkit-flex: 1;
flex: 1;
}
.flex2 {
-webkit-flex: 2;
flex: 2;
}
```
</script></section><section data-markdown><script type="text/template">
demo
<style>
.flex-demo {
margin: 0;
padding: 0 0 1em 0;
font-size: 1em;
line-height: 1.5em;
color: #414142;
font-family: Arial;
background-color: #ededed;
}
.flex-demo * {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.flex-demo .elem p {
padding: 0 1em;
}
.flex-demo p {
margin: 1em 0;
font-size: 0.5em;
}
.flex-demo .elem-green > .label,
.flex-demo .elem-green > .endlabel {
background-color: #FDC72F;
}
.flex-demo .label {
top: 0;
left: 0;
padding: 0 3px 3px 0;
}
.flex-demo .label,
.flex-demo .endlabel {
position: absolute;
background-color: #6AC5AC;
color: #414142;
line-height: 1em;
font-size: 0.5em;
}
.flex-demo .endlabel {
right: 0;
bottom: 0;
padding: 3px 0 0 3px;
}
.flex-demo .elem {
border: solid #6AC5AC 3px;
position: relative;
}
.flex-demo .elem-green {
border: solid #FDC72F 3px;
}
.flex-demo .container {
display: -webkit-flex;
display: flex;
}
.flex-demo .initial {
-webkit-flex: initial;
flex: initial;
width: 200px;
min-width: 100px;
}
.flex-demo .none {
-webkit-flex: none;
flex: none;
width: 200px;
}
.flex-demo .flex1 {
-webkit-flex: 1;
flex: 1;
}
.flex-demo .flex2 {
-webkit-flex: 2;
flex: 2;
}
</style>
<div class="flex-demo">
<div class="container elem">
<div class="elem elem-green initial">
<span class="label"><div class="initial"></span>
<p>
空间足够的时候,我的宽度是200px,如果空间不足,我会变窄到100px,但不会再窄了。
</p>
<span class="endlabel"></div></span>
</div>
<div class="elem elem-green none">
<span class="label"><div class="none"></span>
<p>
无论窗口如何变化,我的宽度一直是200px。
</p>
<span class="endlabel"></div></span>
</div>
<div class="elem elem-green flex1">
<span class="label"><div class="flex1"></span>
<p>
我会占满剩余宽度的1/3。
</p>
<span class="endlabel"></div></span>
</div>
<div class="elem elem-green flex2">
<span class="label"><div class="flex2"></span>
<p>
我会占满剩余宽度的2/3。
</p>
<span class="endlabel"></div></span>
</div>
</div>
</div>
> [learn layout - flexbox](http://zh.learnlayout.com/flexbox.html)
</script></section><section data-markdown><script type="text/template">
主要历史版本
> [20090723 WD](http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/) (display: box;)
> [20110322 WD](http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/) (display: flexbox;)
> [20120918 CR](http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/) (display: flex;)
```
.page-wrap {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
}
```
> [Using Flexbox: Mixing Old and New for the Best Browser Support](http://css-tricks.com/using-flexbox/)
</script></section><section data-markdown><script type="text/template">
### 响应式Web设计(Responsive Web Design)
![responsive](./img/responsive-illustrations.png)
> [Media Type](http://www.w3.org/TR/CSS2/media.html#media-types)
> [Media Query](http://www.w3.org/TR/css3-mediaqueries/)
> [Breakpoint](https://github.com/lolmaus/breakpoint-slicer)
</script></section><section data-markdown><script type="text/template">
### 软键盘
> 打开数字键盘
```
<input type="tel">
```
</script></section><section data-markdown><script type="text/template">
### 隐藏地址栏
```
setTimeout(function(){ window.scrollTo(0, 1); }, 0);
```
</script></section><section data-markdown><script type="text/template">
### apple-touch-icon
> 在iPhone,iPad,iTouch的safari上可以使用添加到主屏按钮将网站添加到主屏幕上
```
<link rel="apple-touch-icon" href="apple-touch-icon-iphone.png" />
<link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-iphone4.png" />
```
</script></section></section><section ><section data-markdown><script type="text/template">
# 交互
</script></section><section data-markdown><script type="text/template">
### touch
> 摩擦、摩擦
</script></section><section data-markdown><script type="text/template">
### tap
> `click` 有 300± ms 延迟
> 服用 [fastclick](https://github.com/ftlabs/fastclick) 后, 可以解决 `click` 的延迟, 还可以防止 `穿透`(跨页面穿透除外), 嘿嘿嘿
</script></section><section data-markdown><script type="text/template">
### scroll
> 区域滚动 `overflow:auto` 不靠谱
> [iscroll](http://iscrolljs.com/)
> [saber-scroll](https://github.com/ecomfe/saber-scroll)
</script></section><section data-markdown><script type="text/template">
### gestures
![gesture](./img/gesture.jpg)
</script></section><section data-markdown><script type="text/template">
> [TouchGestureCards](http://static.lukew.com/TouchGestureCards.pdf) by [lukew](http://www.lukew.com/ff/entry.asp?1370)
> [hammer](http://hammerjs.github.io/). A javascript library for multi-touch gestures
</script></section><section data-markdown><script type="text/template">
### A
* block
> 食指点击目标尺寸是44 x 44像素,拇指是72 x72像素 [finger friendly design](http://www.smashingmagazine.com/2012/02/21/finger-friendly-design-ideal-mobile-touchscreen-target-sizes/)
* `tel:` / `sms:`
</script></section><section data-markdown><script type="text/template">
### HTML5 APIs [(W3C)](http://www.w3.org/2009/dap/)
* 刮一刮 (canvas)
* 摇一摇 (Device Orientation API)
* 咻咻咻 (audio)
* 啪啪啪 (getUserMedia)
</script></section></section><section ><section data-markdown><script type="text/template">
# 实践
</script></section><section data-markdown><script type="text/template">
### -webkit-tap-highlight-color: rgba(255,255,255,0)
> 可以屏蔽点击元素时出现的阴影, 常用于有事件代理的父元素
</script></section><section data-markdown><script type="text/template">
### IMG
* @2x, @3x
> 感谢`apple`一次又次一次 重新发明像素
* font icon
> 矢量图标, 自由变化大小, 颜色;
> 妈妈再也不用担心我的切图
</script></section><section data-markdown><script type="text/template">
### IMG
* base64
> 减少一个请求, 首屏图片无延迟;
> 图片没法gzip,而css可以
* lazyload
> 有流量就会放肆,没流量就会克制
</script></section><section data-markdown><script type="text/template">
### css3
* 合理使用渐变/圆角/阴影
> 别太多, 低端机 hold 不住
* 代替js动画
> 性能好, 兼容好, why not?
* translate3d
> 开启GPU硬件加速, 提升动画渲染性能
* backface-visibility: hidden
> 解决动画闪烁问题
</script></section><section data-markdown><script type="text/template">
### localStorage
* tpl
* data
* js
* img
> 每个域的最大长度为5MB
</script></section><section data-markdown><script type="text/template">
### 避免
* iframe
> 卡 cry, viewport 失效, iOS 宽高失效, fixed定位错误
* fixed + input
> 什么仇什么怨
> 移动商桥 ios/android 分版本 hack
</script></section><section data-markdown><script type="text/template">
### SPA or Multi Page
| | Multi Page (AJAX) | SPA | Isomorphic |
|:---------|:-----------------:|:----------:|:----------:|
| 模板 | 1+ | 1 | 1 |
| 首屏数据 | 同步 | 异步 | both |
| 渲染 | both | client | both |
| 转场 | 差 | 优 | 优 |
| SEO | 优 | 差 | 优 |
| 路由 | 多个 | 多个 | 一致 |
</script></section><section data-markdown><script type="text/template">
### can i use
| feature | can i use |
| ------------ | ----------------------------- |
| es5 | 那些年,每个库都有一个 `each` |
| JSON parsing | 别了, `JSON2` |
| localstorage | 存、存、存,有存,任性 |
| canvas | 和 `Echarts` 愉快的玩耍 |
| GeoLocation | 周围有啥好吃的 |
> [caniuse.com](http://caniuse.com/)
</script></section><section data-markdown><script type="text/template">
### 压缩合并 gzip 14k
> 初始拥塞窗口数 initcwnd = 10
> 最大传输单元 MTU = 1500Bytes
> 首次传输大小 10 * 1500 ~ 14.5Kb
> 返回头 Response Header ~ 0.5Kb
> 内容 Body ~ 14Kb
</script></section><section data-markdown><script type="text/template">
### 2G/3G 下建立连接时间
![goldensecond](./img/goldensecond_mini.png)
> [Creating High-Performance Mobile Websites](http://www.smashingmagazine.com/2013/08/12/creating-high-performance-mobile-websites/)
</script></section></section><section ><section data-markdown><script type="text/template">
# 调试
</script></section><section data-markdown><script type="text/template">
### 二维码
![firfox-debug](./img/firefox-debug.jpg)
</script></section><section data-markdown><script type="text/template">
* [firefox aurora](https://www.mozilla.org/zh-CN/firefox/channel/#aurora)
* [chrome 扩展](https://chrome.google.com/webstore/detail/uc-qr-code/nhelohnehpahakjoklmodmogclacjgdj)
</script></section><section data-markdown><script type="text/template">
### chrome
![chrome-debug](./img/chrome-debug.jpg)
</script></section><section data-markdown><script type="text/template">
### Remote Debugging with Chrome for Android(4.4+)
> <chrome://inspect/#devices>
</script></section><section data-markdown><script type="text/template">
### IOS (6.0.1+) + OS X (Mountain Lion+) + Safari
`IOS端`:
> 设置 → Safari → 高级 → Web 检查器 → 开
`OS X`:
> Safari → 偏好设置 → 高级 → 在菜单栏中显示`开发`菜单
> Safari → 开发 → XXX's Phone → xxx.com
</script></section><section data-markdown><script type="text/template">
### weinre
![weinre-demo](./img/weinre-demo.jpg)
</script></section><section data-markdown><script type="text/template">
> npm 安装
```
npm install -g weinre
```
</script></section><section data-markdown><script type="text/template">
> 启动 weinre 服务
```
weinre --boundHost -all- --httpPort 8081
```
</script></section><section data-markdown><script type="text/template">
> 打开 weinre 服务页面 `http://localhost:8081`
![weire-server](./img/weinre-server.jpg)
</script></section><section data-markdown><script type="text/template">
> 在需要调试页面嵌入 `target script`, 注意 `localhost` 要替换成手机可访问的 `IP`, 打开调试地址, 启动开发者工具, 开始调试吧
</script></section><section data-markdown><script type="text/template">
![weinre-debug](./img/weinre-debug.jpg)
</script></section><section data-markdown><script type="text/template">
> [Weinre Doc](http://people.apache.org/~pmuellr/weinre/docs/latest/)
</script></section><section data-markdown><script type="text/template">
### edp
完成楼上的事情
```
edpm start
```
</script></section></section><section data-markdown><script type="text/template">
# efe mobile
[![saber](./img/saber-qr.png)](http://ecomfe.github.io/saber/)
</script></section><section data-markdown><script type="text/template">
# thx
</script></section></div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme,
transition: Reveal.getQueryHash().transition || 'default',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>