針對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 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() 調用全屏函數



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章