如何检测touchstart并单击事件并相应地应用css

时间:2014-04-22 05:49:48

标签: javascript jquery

var myVideo = document.getElementById('myVideo');
var deviceAgent = navigator.userAgent.toLowerCase();
var event = deviceAgent.match(/(iphone|ipod|ipad)/) ? 'touchstart' : 'click';

$(document).on(event, '.mejs-fullscreen-button', function () {
if (event == 'click') {
  //here it cant catch click event
}//end of click
else {

}//end of touchstart
});

点击或触摸启动事件开始时如何正确映射? 如果(event =='click')在窗口浏览器中无法以任何其他方式编写它?

1 个答案:

答案 0 :(得分:1)

您需要将event传递给您的函数,并使用 event.type

$(document).on(event, '.mejs-fullscreen-button', function (event) {
    if (event.type == 'click') {
        //here it cant catch click event
    }//end of click
    else {

    }//end of touchstart
});