手機端touchstart,touchmove,touchend事件,最佳化使用者劃入某個可以點擊LI的效果

來源:互聯網
上載者:User

標籤:

在我們滑動手機的時候,如果LI或者DIV標籤可以點擊,那麼在移動端給使用者一個效果

/*id為添加效果LI上的UL的ID,或者是當前DIV的ID*/function doTouchPublic(id){    setTimeout(function(){        var obj=document.getElementById(id);            touchPublic.tagUltagDiv(obj);    },300);    };var touchPublic={    tagUltagDiv:function(obj){        var objAll;               /*如果對象為UL,那麼給LI添加事件,否則給DIV當前對象添加事件*/        if(obj.tagName=="UL"){            objAll=obj.childNodes;        }else{            objAll=obj;        }        touchPublic.touchMoveEndIf(objAll);    },    /*li做委託事件,on為JQ中委託事件*/    touchMoveEndIf:function(obj){                        $(obj).on(‘touchstart‘,function(){                touchPublic.touchObjstart(this,"objRowOver");            })            /*觸摸滑動,e.preventDefault();是為了讓end觸發*/            $(obj).on(‘touchmove‘,function(){                touchPublic.touchObjend(this,"objRowOver");            });            /*觸摸離開*/            $(obj).on(‘touchend‘,function(){                touchPublic.touchObjend(this,"objRowOver");            });            },    touchObjstart:function(that,color){        $(that).addClass(color);    },    touchObjend:function(that,color){        if($(that).attr(‘class‘)==color){            $(that).removeClass(color);        }    }}

 

手機端touchstart,touchmove,touchend事件,最佳化使用者劃入某個可以點擊LI的效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.