ontouchstart and ontouchend in jquery?

后端 未结 4 866
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 17:23

I am currently using the following for every element I want to change the class of on touch:

ontouchstart=\"$(this).addClass(\'select\');\" ontouchend=\"$(this).         


        
4条回答
  •  猫巷女王i
    2021-02-15 17:38

    Without JQUERY :

    element.addEventListener('touchstart',function(e) {
     e.currentTarget.className = "select";
    });
    

    With JQUERY

    $('#nav ul li a').on('touchstart', function(){
        $(this).addClass('select');
    });
    

    Actually, on() get better performance than bind(), check documentation

提交回复
热议问题