手機端開發筆記-迭代記錄

來源:互聯網
上載者:User

標籤:狀態列   大小   browser   trait   模式   沒有   order   ios   記憶體   

1、防止手機中網頁放大和縮小,這點是最基本的,最為手機網站開發人員來說應該都知道的,就是設定meta中的viewport 視口

有些手機網站我們看到如下聲明:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

設定了DTD的方式是XHTML的寫法,假如我們頁面運用的是 html5,可以不用設定DTD,直接聲明 <!DOCTYPE html>。

使用viewport使頁面禁止縮放。 通常把user-scalable設定為0來關閉使用者對整頁模式縮放的行為。

完整的viewport設定,當然,user-scalable=0,有的人也寫成user-scalable=no,都可以的。

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

2、蘋果手機的一些設定。

<meta name="apple-mobile-web-app-capable" content="yes">

如果content設定為yes,Web應用會以全螢幕模式運行,反之,則不會。content的預設值是no,表示正常顯示。你可以通過唯讀屬性window.navigator.standalone來確定網頁是否以全螢幕模式顯示。

3、format-detection設定。

<meta name="format-detection" content="telephone=no">

<meta name="format-detection" content="email=no">

format-detection 啟動或禁用自動識別頁面中的電話號碼、郵箱地址。

4、上下拉動捲軸時卡頓、慢

body {
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}

Android3+和iOS5+支援CSS3的新屬性為overflow-scrolling

5、禁止複製、選中文本

Element {
-webkit-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
user-select: none;
}

*:not(input,textarea){
-moz-user-select: none;
-o-user-select:none;
-khtml-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
user-select:none;
}

解決行動裝置可選中頁面文本(視產品需要而定)

6、長時間按住頁面出現閃退

element {
-webkit-touch-callout: none;
}

7、iphone及ipad下輸入框預設內陰影

Element{
-webkit-appearance: none;
}

8、ios和android下觸摸元素時出現半透明灰色遮罩

Element {
-webkit-tap-highlight-color:rgba(255,255,255,0)
}

9、active相容處理 即 偽類 :active 失效

方法一:body添加ontouchstart

<body ontouchstart="">

方法二:js給 document 綁定 touchstart 或 touchend 事件

<style>
a {
color: #000;
}
a:active {
color: #fff;
}
</style>
<a herf=foo >bar</a>
<script>
document.addEventListener(‘touchstart‘,function(){},false);
</script>

10、動畫定義3D啟用硬體加速

Element {
-webkit-transform:translate3d(0, 0, 0)
transform: translate3d(0, 0, 0);
}
注意:3D變形會消耗更多的記憶體與功耗

11、Retina屏的1px邊框

Element{
border-width: thin;
}

12、旋轉螢幕時,字型大小調整的問題

*{
-webkit-text-size-adjust:100%;
}

13、頂部狀態列背景色

<meta name="apple-mobile-web-app-status-bar-style" content="black" />

說明:

除非你先使用apple-mobile-web-app-capable指定全螢幕模式,否則這個meta標籤不會起任何作用。

如果content設定為default,則狀態列正常顯示。如果設定為blank,則狀態列會有一個黑色的背景。如果設定為blank-translucent,則狀態列顯示為黑色半透明。如果設定為default或blank,則頁面顯示在狀態列的下方,即狀態列佔據上方部分,頁面佔據下方部分,二者沒有遮擋對方或被遮擋。如果設定為blank-translucent,則頁面會充滿螢幕,其中頁面頂部會被狀態列遮蓋住(會覆蓋頁面20px高度,而iphone4和itouch4的Retina螢幕為40px)。預設值是default。

相容性 iOS 2.1 +

14、設定緩衝

<meta http-equiv="Cache-Control" content="no-cache" />

手機頁面通常在第一次載入後會進行緩衝,然後每次重新整理會使用緩衝而不是去重新向伺服器發送請求。如果不希望使用緩衝可以設定no-cache。

15、案頭表徵圖

<link rel="apple-touch-icon" href="touch-icon-iphone.png" />
<link rel="apple-touch-icon" sizes="76x76" href="touch-icon-ipad.png" />
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png" />

16、瀏覽器私人及其它meta

QQ瀏覽器私人

 

全螢幕模式

<meta name="x5-fullscreen" content="true">
強制豎屏

<meta name="x5-orientation" content="portrait">
強制橫屏

<meta name="x5-orientation" content="landscape">
應用模式

<meta name="x5-page-mode" content="app">
UC瀏覽器私人

全螢幕模式

<meta name="full-screen" content="yes">
強制豎屏

<meta name="screen-orientation" content="portrait">
強制橫屏

<meta name="screen-orientation" content="landscape">
應用模式

<meta name="browsermode" content="application">
其它

針對手持功能最佳化,主要是針對一些老的不識別viewport的瀏覽器,比如黑莓

<meta name="HandheldFriendly" content="true">
微軟的老式瀏覽器

<meta name="MobileOptimized" content="320">
windows phone 點擊無高光

<meta name="msapplication-tap-highlight" content="no">

17、IOS中input鍵盤事件keyup、keydown、keypress支援不是很好

問題是這樣的,用input search做模糊搜尋的時候,在鍵盤裡面輸入關鍵詞,會通過ajax後台查詢,然後返回資料,然後再對返回的資料進行關鍵詞標紅。用input監聽鍵盤keyup事件,在安卓手機瀏覽器中是可以的,但是在ios手機瀏覽器中變紅很慢,用IME輸入之後,並未立刻相應keyup事件,只有在通過刪除之後才能相應!

解決方案:可以用html5的oninput事件去代替keyup

<input type="text" id="testInput">
<script type="text/javascript">
document.getElementById(‘testInput‘).addEventListener(‘input‘, function(e){
var value = e.target.value;
});
</script>
18‘ 手機上顯示藍色的數字(7位元;蘋果手機會預設為電話號碼;可以點擊撥打;後台請求的日期也是藍色) 解決:

<meta name = "format-detection" content = "telephone=no,date=no,address=no,email=no">

19 捲軸蘋果手機上滾動不順暢 加上以下屬性就可以了;
-webkit-overflow-scrolling : touch;

20.
/*a連結點擊圖片出現閃一下*/
html{-webkit-tap-highlight-color:none}
html{-webkit-tap-highlight-color:transparent;}

手機端開發筆記-迭代記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.