<!--1:設置視口寬度 縮放比例-->
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<!--2:忽略將數字變爲電話號碼-->
<meta content="telephone=no" name="format-detection">
<!--3:忽略識別郵箱-->
<meta name="format-detection" content="email=no" />
<!--4:IOS中Safari容許全屏瀏覽-->
<meta content="yes" name="apple-mobile-web-app-capable">
複製代碼
移動端瀏覽器會有一些默認的行爲,好比雙擊縮放、雙擊滾動。這些行爲,尤爲是雙擊縮放,主要是爲桌面網站在移動端的瀏覽體驗設計的。而在用戶對頁面進行操做的時候,移動端瀏覽器會優先判斷用戶是否要觸發默認的行爲。css
問題點擊穿透問題:點擊蒙層(mask)上的關閉按鈕,蒙層消失後發現觸發了按鈕下面元素的click事件html
zepto的tap事件是綁定到document的,因此通常點擊tap事件都會冒泡到document纔會觸發。當點擊隱藏蒙層的時候默認也會手指觸發到蒙層下面的元素 執行事件
複製代碼
//tap事件出現點透問題
$("#id").on("tap", function (event) {
//不少處理好比隱藏什麼的
event.preventDefault();
});
//touchend事件解決點頭問題
$("#id").on("touchend", function (event) {
//不少處理好比隱藏什麼的
event.preventDefault();
});
複製代碼
$("#id").on('tap',function(ev){
setTimeout(function(){
$("#id").hide();
},320)
})
複製代碼
window.onresize = function(){
//$(".mian")就是固定定位的元素
if($(".mian").css('top').replace('px','') != 0){
$(".mian").css('top',0);
}else{
var winHeight = $(window).height();
$(".mian").css('top',-(winHeight/4));
}
}
複製代碼
function fixedWatch(el) {
//activeElement 獲取焦點元素
if(document.activeElement.nodeName == 'INPUT') {
el.css('position', 'static');
} else {
el.css('position', 'fixed');
}
}
setInterval(function() {
fixedWatch($('.mian'));
}, 500);
複製代碼
//去掉webkit的滾動條——display: none;
//其餘參數
::-webkit-scrollba //滾動條總體部分
::-webkit-scrollbar-thumb //滾動條內的小方塊
::-webkit-scrollbar-track //滾動條軌道
::-webkit-scrollbar-button //滾動條軌道兩端按鈕
::-webkit-scrollbar-track-piece //滾動條中間部分,內置軌道
::-webkit-scrollbar-corner //邊角,兩個滾動條交匯處
::-webkit-resizer //兩個滾動條的交匯處上用於經過拖動調整元素大小的小控件
// 禁止長按連接與圖片彈出菜單
a,img { -webkit-touch-callout: none }
// 禁止ios和android用戶選中文字
html,body {-webkit-user-select:none; user-select: none; }
// 改變輸入框placeholder的顏色值
::-webkit-input-placeholder { /* WebKit browsers */
color: #999; }
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #999; }
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #999; }
:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #999; }
input:focus::-webkit-input-placeholder{ color:#999; }
// android上去掉語音輸入按鈕
input::-webkit-input-speech-button {display: none}
// 阻止windows Phone的默認觸摸事件
/*說明:winphone下默認觸摸事件事件使用e.preventDefault是無效的,可經過樣式來禁用,如:*/
html { -ms-touch-action:none; } //禁止winphone默認觸摸事件
//ios用戶點擊一個連接,會出現一個半透明灰色遮罩, 若是想要禁用,可設置-webkit-tap-highlight-color的alpha值爲0去除灰色半透明遮罩;
//android用戶點擊一個連接,會出現一個邊框或者半透明灰色遮罩, 不一樣生產商定義出來額效果不同,可設置-webkit-tap-highlight-color的alpha值爲0去除部分機器自帶的效果;
//winphone系統,點擊標籤產生的灰色半透明背景,能經過設置<meta name="msapplication-tap-highlight" content="no">去掉;
//特殊說明:有些機型去除不了,如小米2。對於按鈕類還有個辦法,不使用a或者input標籤,直接用div標籤
a,button,input,textarea {
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-user-modify:read-write-plaintext-only; //-webkit-user-modify有個反作用,就是輸入法再也不可以輸入多個字符
}
// 也能夠
* { -webkit-tap-highlight-color: rgba(0,0,0,0); }
//winphone下
<meta name="msapplication-tap-highlight" content="no">
複製代碼
/*
*IOS有拍照、錄像、選取本地圖片功能,
*部分Android只有選擇本地圖片功能。
*Winphone不支持
*/
<input type="file" accept="images/*" />
複製代碼
.css {
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
}
======一下內容與上無關=====
//目前,像Chrome/Filefox/Safari/IE9+以及最新版本Opera都支持硬件加速,當檢測到某個DOM元素應用了某些CSS規則時就會自動開啓,從而解決頁面閃白,保證動畫流暢。
.css {
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
複製代碼
寫好一套樣式 獲取窗口的寬度大於高度的時候 說明橫屏了 。那麼就顯示一個遮罩層提示用戶 豎屏觀看更佳。node