【技术】手机网页应用:针对webkit的HTML, CSS和Javascript
前面有一篇文章介绍了HTML5的一些新特性以及技巧, 现再来总结一些更多的针对webkit的HTML, CSS和Javascript方面的特性.
HTML, 从HTML文档的开始到结束排列:
<meta name="”viewport”" content="”width=device-width," initial-scale="1.0″/" />
让内容的宽度自适应为设备的宽度, 在做Mobile Web时必须加的一条
<meta name="”format-detection”" content="”telephone=no”]]" />
禁用手机号码链接(for iPhone)
<link href="”icon.png”/" rel="”apple-touch-icon”" /> 设置你网页的图标, 尺寸为57X57 px
<!--– iOS 2.0+: tell iOS not to apply any glare effects to the icon –-->
<link href="”icon.png”/" rel="”apple-touch-icon-precomposed”" />
<!--– iOS 4.2+ icons for different resolutions –-->
<link href="”touch-icon-ipad.png”" rel="”apple-touch-icon”" sizes="”72×72″" />
<link href="”touch-icon-iphone4.png”" rel="”apple-touch-icon”" sizes="”114×114″" />
<link href="”startup.png”" rel="”apple-touch-startup-image”" /> 全屏启动时候的启动画面图像, 尺寸320X460 px
<meta name="”apple-mobile-web-app-capable”" content="”yes”" />
是否允许全屏显示, 只有在桌面启动时可用
<meta name="”apple-mobile-web-app-status-bar-style”" content="”black”" />
控制全屏时顶部状态栏的外观, 默认白色
<input autocapitalize="”off”" autocomplete="”off”" autocorrect="”off”" /> 取消自动完成, 自动大写单词字母(适用于Mobile上)
<input type="”text”" x-webkit-speech="" /> 语音输入
<input type="”file”" accept="“image/*;" capture="camera”" /> 文件上传, 从相机捕获媒体, 下同
<input type="”file”" accept="“video/*;" capture="camcorder”" />
<input type="”file”" accept="“audio/*;" capture="microphone”" />
Call us at 1-800-555-5555 拨打电话 的链接
-webkit-tap-highlight-color: transparent; Mobile上点击链接高亮的时候设置颜色为透明
-webkit-user-select: none; 设置为无法选择文本
-webkit-touch-callout: none; 长按时不触发系统的菜单, 可用在图片上加这个属性禁止下载图片
:-webkit-full-screen canvas {} 全屏模式时的样式(for Desktop)
div p :matches(em, b, strong) {} 使用mathes来匹配多个选择器
@media only screen and (max-width: 480px) {} 指定Mobile设备或者小屏幕桌面屏幕
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 300dpi) { 指定高分辨率屏幕设备
header { background-image: url(header-highres.png); }
@media (-webkit-max-device-pixel-ratio: 1.5),(max-resolution: 299dpi) { 指定低分辨率屏幕设备
header { background-image: url(header-lowres.png); }
background-repeat: space; background-repeat: round; 这两种CSS3的背景属性值得研究
text-decoration: #FF8800 wavy ine-through; 波浪型链接
text-rendering: optimizeLegibility; 用这个属性之后会收紧字符间的距离
font-variant-ligatures: common-ligatures; 设置CSS连字
transform: rotate(90); 旋转90度
transform-origin: center center; transform-origin可以改变变换的位置
-webkit-appearance: none; -webkit-appearance可以改变按钮或者其它控件看起来类似本地的控件
美化表单校验时的提示样式
::-webkit-validation-bubble {} ::-webkit-validation-bubble-message {} ::-webkit-validation-bubble-arrow {} ::-webkit-validation-bubble-arrow-clipper {}
当提示出现时类似于下面的结构
Error Message
自定义webkit浏览器的滚动条, 见Google Reader等在Chrome/Safari下的效果, 下面是一个实例, 这个滚动条的样式代码如下:
Customized WebKit Scrollbar /* Let´s get this party started */ ::-webkit-scrollbar { width: 12px; } /* Track */ ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); -webkit-border-radius: 10px; border-radius: 10px; } /* Handle */ ::-webkit-scrollbar-thumb { -webkit-border-radius: 10px; border-radius: 10px; background: rgba(255,0,0,0.8); -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); } ::-webkit-scrollbar-thumb:window-inactive { background: rgba(255,0,0,0.4); }
-webkit-background-composite: plus-darker; -webkit-background-composite用来设置一个元素的背景或颜色的组合样式
-webkit-text-stroke: 1px rgba(0,0,0,0.5); -webkit-text-stroke可以用来给文字添加描边
-webkit-mask-image: url(/path/to/mask.png); 定义一个图片用来遮罩元素
-webkit-box-reflect: below 5px; 定义了一个元素的反射
:local-link {font-weight: normal;} local-link可以定义相对地址的链接样式
Javascript:
window.scrollTo(0,0); 隐藏地址栏
window.matchMedia(); 匹配媒体
navigator.connection; 决定手机是否运行在WiFi/3G等网络
window.devicePixelRatio; 决定屏幕分辨率(iPhone 4值为2, 而Nexus One值为1.5)
window.navigator.onLine; 取得网络连接状态
window.navigator.standalone; 决定iPhone是否处于全屏状态
touch事件 (iOS, Android 2.2+): touchstart, touchmove, touchend, touchcancel
gesture事件 (Apple only, iOS 2+): gesturestart, gesturechange, gesturend give access to predefined gestures (rotation, scale, position)
window.addEventListener("orientationchange", function(e){ //window.orientation(0 is portrait, 90 and -90 are landscape) }, false); window.addEventListener("deviceorientation", function(e){ //e.alpha //e.beta //e.gamma }, false); window.addEventListener("devicemotion", function(e){ //e.accelerationIncludingGravity.x //e.accelerationIncludingGravity.y //e.accelerationIncludingGravity.z }, false);
requestAnimationFrame() 新的动画函数
element.webkitRequestFullScreen() 调用全屏函数
阅读更多:
http://www.slideshare.net/franksvalli/mobile-html-css-and-javascript
http://css-tricks.com/9130-custom-scrollbars-in-webkit/
https://developer.mozilla.org/zh-CN/docs
一些惊艳的h5 demo效果:
找不到之前所见过的网页,深有同感!
Animated Books with CSS 3D Transforms 这是一个3D书本,CSS3完成
=========HTML5特效聚集网站========
christmasexperiments.com 的页面
chromeexperiments.com 的页面
Mr.doob
litewerx.showcase
Form Follows Function
AlteredQualia
html5rocks.com 的页面
===========视觉特效与交互式视频============
http://www.thewildernessdowntown.com/
Interactive Film "itsumo kawaii"
http://www.beonlineb.com/
Arcade Fire / Just a Reflektor
Aaronetrope 3D科幻视频投影对话
Aleksandar Rodic 3D立体博客
Beanstalk
http://www.ro.me/
three.js webgl 动态地图
Ô Green by SPECIAL.T 水中植物广告
Kimatica - Creative Connections 树脉
Earth to Echo 电影科幻宣传网站
http://middle-earth.thehobbit.com/map 霍比特人
HelloRun™ 线稿房间,第一人称动
LETTERS, INC. 集成电路
Dataveyes | Human Data Interactions 视觉粒子
=========音乐与可视化==========
http://do.adive.in/
Rocking dendrites 摇滚与触手
Arabesque - Music Colour Particles 优美的纯音乐与彩色烟雾
compo.filler 蓝电之音
Lights 波点
ĂberViz 电子
A [ Radiohead 音乐画画
=========物理特性元素============
Blob 大水球
Andrew Hoyer 布-骨架
HTML5 Fish Bowl IE-鱼缸
googlecode.com 的页面 chrome-水族馆
three.js webgl 动物
Liquid Particles 3D 3D粒子流
==========画绘与生成===========
10 Jaw Dropping HTML5 and Javascript Effects 10个画绘特效
wormz . html5 canvas experiment 图片生成毛毛虫~~
Silk – Interactive Generative Art 光效
Sketch Toy: Draw sketches and share replays with friends! 记录线稿步骤
ASCIIFlow Infinity ASCII字符生成图表
Andrew McCarthy 滚动动物奔跑
http://tokyomildfoundation.com/ 东京温柔基金
fifty-five | the data agency 垂直分割
A P R I L Z E R O 数据分析
Gaming Media 创意横向滚动
Luxaqua | Aquarium Design 深邃海底纵向滚动
KILFISH 鬼畜纵向滚动
有顆梅,在台灣 食品纵向滚动
Vespillo le film Vespillo纵向滚动
Exploring Moon Bears IE-月熊志
Metal Junk: The Game HTML5游戏:金属废墟,游戏就不展开了~~