最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can use hammer.js pan events and still allow users to scroll? - Stack Overflow

programmeradmin0浏览0评论

I have a UI where users are scrolling a horizontally scrolling area.

I still want them to be able to scroll left and right, but I'd like to fire an Hammer.js pan event at the same time. Here's my code at present:

var worksHammertime = new Hammer(scrollingArea);
worksHammertime.on('pan', function(ev) {
  if ( ev.direction === 2 ) {
    log('left', ev)
    Do things...
  } else {
    log('right', ev)
    Do things...
  }
});

Essentially I think I'm looking for the opposite of the preventDefault()behaviour that Hammer seems to use by default. Can use hammer.js pan events and still allow users to scroll?

I have a UI where users are scrolling a horizontally scrolling area.

I still want them to be able to scroll left and right, but I'd like to fire an Hammer.js pan event at the same time. Here's my code at present:

var worksHammertime = new Hammer(scrollingArea);
worksHammertime.on('pan', function(ev) {
  if ( ev.direction === 2 ) {
    log('left', ev)
    Do things...
  } else {
    log('right', ev)
    Do things...
  }
});

Essentially I think I'm looking for the opposite of the preventDefault()behaviour that Hammer seems to use by default. Can use hammer.js pan events and still allow users to scroll?

Share Improve this question asked Jul 16, 2014 at 19:43 mikemaccanamikemaccana 124k110 gold badges430 silver badges533 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Apply a CSS property:

#touch-area
{
touch-action: pan-x pan-y !important;
}

This currently isn't supported, but you could try to do this with a nested element containing style="overflow: auto;"

发布评论

评论列表(0)

  1. 暂无评论