javascript - HTML with event.preventDefault - Stack Overflow

If the html document is disabled. (no scrolling...)document.ontouchmove = function(event){ event.preven

If the html document is disabled. (no scrolling...)

document.ontouchmove = function(event){ event.preventDefault(); }

Can I selectively enabled elements in the html document? such as a div, span What javascript should I use to do that?

If the html document is disabled. (no scrolling...)

document.ontouchmove = function(event){ event.preventDefault(); }

Can I selectively enabled elements in the html document? such as a div, span What javascript should I use to do that?

Share Improve this question asked Aug 18, 2010 at 2:30 YazzmiYazzmi 1,5715 gold badges18 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Here’s a fairly hacky solution.

Change your touchmove handler as follows:

document.ontouchmove = function (event) {
    if (!event.elementIsEnabled) {
        event.preventDefault();
    }
};

Then for an element that you want to enable:

element.ontouchmove = function (event) {
    event.elementIsEnabled = true;
};

This works because:

  • When a touchmove event is fired on the element, both of these event handlers handle the event in the bubbling phase. This means that the element touchmove handler fires first, because it is closest to the source of the event.
  • When two event handlers handle the same event, they receive the same event object.
  • You’re allowed to set your own arbitrary properties on an event object.

So, the element touchmove handler just sets a custom property on the event object, and then the document touchmove handler checks for that custom property to determine whether the default action should be prevented.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745087370a4610484.html

相关推荐

  • javascript - HTML with event.preventDefault - Stack Overflow

    If the html document is disabled. (no scrolling...)document.ontouchmove = function(event){ event.preven

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信