首页 > 给一个dom元素绑定了touch事件,然后再怎么绑定click事件

给一个dom元素绑定了touch事件,然后再怎么绑定click事件

除了tap方法还有什么比较好的方法

var imgObj = document.getElementsByClassName("car_img");
var imgLen = imgObj.length;
$(".car_img").on("tap",function(event){
        var openHref = $(this).data("href");
        window.location.href = openHref;
    });
    int = setInterval(carouselImg,3000);
    for(var i=0;i<imgLen;i++){
        $(".car_img").eq(i).css({"top":"0","left":i*windowWidth});
        imgObj[i].addEventListener('touchstart',touchstart,false);
        imgObj[i].addEventListener('touchmove',touchmove,false);
        imgObj[i].addEventListener('touchend',touchend,false);
    }

这个是可以点击跳转新页面的,但我想用click事件来绑定跳转新页面,该怎么写??
详细函数代码:https://.com/a/1190000004475501


一个DOM元素可以绑定多个不同事件类型的,只要这个事件类型DOM元素能够响应

$(".car_img").on("tap",function(event){
        var openHref = $(this).data("href");
        window.location.href = openHref;
});
$(".car_img").on("click",function(event){
        var openHref = $(this).data("href");
        window.location.href = openHref;
});

可以考虑外挂个fastclick,这样写一个click就能同时对应pc和移动端了;如果需求更复杂时可以考虑上hammer.js这个手势库。个人不太建议用zepto的tap。

【热门文章】
【热门文章】