Prevent touchmove default on parent but not child

后端 未结 5 2053
猫巷女王i
猫巷女王i 2020-12-15 17:22

I am creating a little web app for the iPad and I\'ve got several elements I am preventing the user from scrolling by preventing default on the touchmove event. However, I h

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 18:02

    Try this:

    $('#fix').on('touchmove',function(e){
        if(!$('.scroll').has($(e.target)).length)
            e.preventDefault();
    });
    

    EDITED

    e.target contains the final target node of the touch event. You can stop all events that are not "bubbling accross" your .scroll divs.

    I think there are better solutions, but this one must be ok.

提交回复
热议问题