针对webkit的HTML, CSS和Javascript

来源:互联网 发布:数据元与元数据的区别 编辑:程序博客网 时间:2024/04/26 15:14

 

前面有一篇文章介绍了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 rel=”apple-touch-icon” href=”icon.png”/>       <!--设置你网页的图标, 尺寸为57X57 px  -->      <!– iOS 2.0+: tell iOS not to apply any glare effects to the icon –>        <link rel=”apple-touch-icon-precomposed” href=”icon.png”/>        <!– iOS 4.2+ icons for different resolutions –>        <link rel=”apple-touch-icon” sizes=”72×72″ href=”touch-icon-ipad.png” />        <link rel=”apple-touch-icon” sizes=”114×114″ href=”touch-icon-iphone4.png” />        <link rel=”apple-touch-startup-image” href=”startup.png”>       <!--全屏启动时候的启动画面图像, 尺寸320X460 px  -->      <meta name=”apple-mobile-web-app-capable” content=”yes” />       <!--是否允许全屏显示, 只有在桌面启动时可用 -->       <meta name=”apple-mobile-web-app-status-bar-style” content=”black” />       <!--控制全屏时顶部状态栏的外观, 默认白色  -->      <input autocorrect=”off” autocomplete=”off” autocapitalize=”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” />        <a href=”sms:18005555555,18005555556″]]>       <!--发送短信给多个人的链接 -->      <a href=”sms:18005555555?body=Text%20goes%20here”]]>       <!--发送短信附带内容的链接 -->      <a href=”tel:18005555555″]]>Call us at 1-800-555-5555</a]]>       <!--拨打电话的链接 -->   

CSS:

    -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的背景属性值得研究*/            width: calc(100%-40px);       /*计算宽度*/            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 {}

当提示出现时类似于下面的结构

<div -webkit-validation-bubble>  <div -webkit-validation-bubble-arrow></div>   <div -webkit-validation-bubble-arrow-clipper></div>  <div -webkit-validation-bubble-message>Error Message</div>   </div> 

自定义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() 调用全屏函数