代码搜集-手机网页触屏

function initTouchEvent(){
    if(!!('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch){
        var items = $(".article_item");
        for(var i=0;i<items.length;i++){
            addToucheEvent(items[i],$(items[i]).attr("id"));
        }
    }
}

function addToucheEvent(item,id){
    item.addEventListener('touchstart',touch, false);
    item.addEventListener('touchend',touch, false);
    item.addEventListener('touchmove',touch, false);

    function touch (event){
        var event = event || window.event;
        switch(event.type){
            case "touchstart":
                $("#"+id).css({"background":"#F5F5F5"});
                break;
            case "touchend":
                $("#"+id).css({"background":"#FFF"});
                break;
            case "touchmove":
                //event.preventDefault();
                $("#"+id).css({"background":"#FFF"});
                break;
        }
    }
}

 

posted @ 2015-04-02 18:30  周雷  阅读(380)  评论(0编辑  收藏  举报
友情链接