This is a presentation to review and summarize the mobile websites that I have involved in. It includes many practical skills and my own experiences in the development of mobile websites.
10. Native App
定义:Apps developed exclusively for
a specific mobile platform that can
leverage all device capabilities.
11. Web vs. Native
Web Native
Dev Cost Reasonable Expensive
Dev Time Short Long
Portability High No
Performance Fast Very Fast
Native Functionality No All
Distribution No Yes
12. Hybrid App
定义: Apps that wrap a mobile web
interface inside a native container.
14. Web vs. Hybrid vs. Native
Web Hybrid Native
Dev Cost Reasonable Reasonable Expensive
Dev Time Short Short Long
Portability High High No
Performance Fast Fast Very Fast
Native
Functionality No Yes All
Distribution No Yes Yes
15. Web vs. Hybrid vs. Native
这个世界上,从来没有最好的技术或是编程
语言,只有最恰当的选择和与之匹配的解决
方案。
16. 目录
• Web Applications?
• HTML5
• Web APP开发
• 最佳实践
• PhoneGap
17. What is HTML5
HTML5 ~= HTML + CSS3 + JS API
详细:http://slides.html5rocks.com/#landing-slide
18. HTML5 for Mobile Browsers
OS or Browser Platform Score
(*/500)
BlackBerry 10.1 » BlackBerry Q or Z series 485
Opera Mobile 15 » Android 428
Firefox Mobile 22 » Multiple platforms 422
Chrome 25 » All Android 4 devices 417
Opera Mobile 12.10 » Multiple platforms 406
iOS 6.0 » Apple iPhone, iPad and iPod Touch 386
iOS 5.0 » Apple iPhone, iPad and iPod Touch 258
Windows Phone 8 » Nokia Lumia 822, HTC 8X and
others 320
Android 4.0 » Samsung Galaxy Nexus 297
http://html5test.com/
19. HTML5 Elements for Mobile
• Offline Support: Web database,
LocalStorage, App Cache
• Canvas
• Video
• GeoLocation
• Advanced Forms
• Workers
• Camera
20. 目录
• Web Applications?
• HTML5
• Web APP开发
• 最佳实践
• PhoneGap
26. Web APP开发#1
• Small Screen CSS
o media queries
<link media=“only screen and (max-device-width: 480px)”
href=“mobile.css” type=“text/css” rel=“stylesheet”/>
<link media=“screen and (min-device-width: 481px)”
href=“standard.css” type=“text/css” rel=“stylesheet”/>
27. Web APP开发#1
• Small Screen CSS
o media query
@media only screen and (max-device –width: 480px){
#test{
color: red;
}
}
28. Web APP开发#2
• UserAgent
1. Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebkit/420.1 (KHTML,
like Gecko) Version/3.0 Mobile/4A93 Safari/419.3
2. Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebkit/420+ (KHTML,
like Gecko) Version/3.0 Mobile/1A543 Safari/419.3
3. Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebkit/
531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
Javascript:
If((navigator.userAgent.match(/iPhone/i))){}
29. Web APP开发#2
var pixelRatio = window.devicePixelRatio || 1;
var iPhone = /iPhone/i.test(navigator.userAgent);
var iPhone4 = (iPhone && pixelRatio == 2);
var iPhone5 = /iPhone OS 5_0/i.test(navigator.userAgent);
var iPad = /iPad/i.test(navigator.userAgent);
var android = /android/i.test(navigator.userAgent);
var webos = /hpwos/i.test(navigator.userAgent);
var iOS = iPhone || iPad;
var mobile = iOS || android || webos;
30. Web APP开发#3
• iPhone Browser & Viewport meta
Status Bar: 20px
URL Bar: 60px
Viewport: 320*356px
Button Bar: 44px
iPhone
(非retina):
320*480px
31. Web APP开发#3
• Viewport Meta
<meta name=“viewport” content=”width=device-width” />
40. Web APP开发#8
• Orientation
function checkOrientation(){
switch(window.orientation){
case 0:
alert(‘Orientation: Portrait’);
break;
case 90:
case -90:
alert(‘Orientation: Landscape’);
break;
}
}
addEventListener(‘orientationchange’, checkOrientation);
46. Web APP开发#13
• Retina: background images
.repeatingPattern {
background: url(../images/bgPattern.png) repeat;
background-size: 100px 100px;
}
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
.repeatingPattern {
background: url(../images/bgPattern@2x.png) repeat;
}
}
47. Web APP开发#13
• Retina: inline images
o JS for image replacement
if (window.devicePixelRatio === 2) {
//Replace your img src with the new retina image
}
49. Web APP开发#14
• CSS动画
o CSS Transitions
o CSS 2D Transformations
o CSS 3D Transformations
o CSS Animations
• 效果案例
兼容性: http://caniuse.com/
50. Web APP开发#14
• CSS 3D Transformations(开启GPU加速)
• -webkit-transform:
o translate3d(tx,ty,tz);
o scale3d(sx,sy,sz);
o rotate3d(rx,ry,rz,angle);
• Demo
51. Web APP开发#15
• 调试
o Chrome调试工具
o weinre: Web Inspector Remote, 远程实时调试
59. 目录
• Web Applications?
• HTML5
• Web APP开发
• 最佳实践
• PhoneGap
60. What is PhoneGap
PhoneGap is a free and open source framework
that allows you to create mobile apps using
standardized web APIs for the platforms you care
about.
http://phonegap.com/
63. PhoneGap APIS
Accelerometer
Tap into the device’s motion sensor
Camera
Capture a photo using the device’s camera
Compass
Obtain the direction that the device is pointing
Contacts
Work with the devices contact database
Device
Gather device specific information
Event
Hook into native events through JavaScript
File
Hook into native file system through JavaScript
Geolocation
Make your application location aware
Media
Record and play back auto files
Network
Quickly check the network state
Notification
Visual, audible, and tactile device notification
Storage
Hook into the device’s native storage options