does mousedown /mouseup in jquery work for the ipad?

前端 未结 4 1606
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 16:41

I am using the current code:

$(\'body\').mousedown(function() {
        $(\'div#extras\').fadeTo(\'fast\', 1);
});

$(\'body\').mouseup(function() {
                 


        
4条回答
  •  醉梦人生
    2020-12-04 17:16

    Old post but there is universal solution:

    $('body').on('mousedown touchstart',function(e){
        $('div#extras').fadeTo('fast', 1);
    });
    $('body').on('mouseup touchend',function(e){
        $('div#extras').delay(2000).fadeTo(1500, 0);
    });
    

    You will notice that I use mousedown with touchstart and mouseup with touchend. This cover mobile and desktop use.

提交回复
热议问题