移動端 觸摸事件 ontouchstart、ontouchmove、ontouchend、ontouchcancel

一、Touch事件簡介

pc上的web頁面鼠 標會產生onmousedown、onmouseup、onmouseout、onmouseover、onmousemove的事件,可是在移動終端如 iphone、ipod  Touch、ipad上的web頁面觸屏時會產生ontouchstart、ontouchmove、ontouchend、ontouchcancel 事件,分別對應了觸屏開始、拖拽及完成觸屏事件和取消。
當按下手指時,觸發ontouchstart;
當移動手指時,觸發ontouchmove;
當移走手指時,觸發ontouchend。
當一些更高級別的事件發生的時候(如電話接入或者彈出信息)會取消當前的touch操做,即觸發ontouchcancel。通常會在ontouchcancel時暫停遊戲、存檔等操做。
 
二、Touch事件與Mouse事件的出發關係
在觸屏操做後,手指提起的一剎那(即發生ontouchend後),系統會判斷接收到事件的element的內容是否被改變,若是內容被改變,接下來的事 件都不會觸發,若是沒有改變,會按照mousedown,mouseup,click的順序觸發事件。特別須要提到的是,只有再觸發一個觸屏事件時,纔會 觸發上一個事件的mouseout事件。
相關文章
相關標籤/搜索