overview
因為在移動端,我們沒有hover的狀態(tài),但是往往我們需要對用戶的點擊作出反饋,讓用戶知道自己點擊到了按鈕
resolve
解決方案其實就是使用:active偽類,但是使用:active有幾個注意事項
IOS中,:active狀態(tài)只在touch event設(shè)置后才觸發(fā)
On iOS, mouse events are sent so quickly that the down or active state is never received.
在 Safari Developer Library的Highlighting Elements部分最后有提到,因為mouse事件發(fā)送太快,所以active不會被接收到
解決方式就是顯示設(shè)置touchstart事件,告訴瀏覽器去相應(yīng)這個事件,可以直接寫在body上
<body ontouchstart="">
...
</body>
也可以在直接在入口script文件設(shè)置
document.addEventListener('touchstart', function () {} )
button按鈕存在默認反饋狀態(tài)
IOS中的button按鈕在默認情況下已經(jīng)有了反饋的狀態(tài),表現(xiàn)為一層灰色遮罩,在移動端的safari點擊會觸發(fā)
解決方法是使用私有屬性把遮罩設(shè)置為透明
html {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}