3

I'm using HammerJS to detect left swipes on touch screen devices. I'm trying to open a slide-out menu every time the user swipes left anywhere on the page when browsing on a touch-screen device. It works fine in portrait mode but not in landscape. I thought it might be because the direction might be changing from left to up/down, however the alert doesn't happen at all when the device is landscape. There is a fixed-position menu bar at the top of the page and it always works when swiping left on that, but not on the rest of the page. The same problem occurs on iOS Safari, and on Android Browser, Chrome, and Firefox.

I noticed on the HammerJS documentation it says "When calling Hammer() to create a simple instance, the pan and swipe recognizers are configured to only detect horizontal gestures." (http://hammerjs.github.io/recognizer-pan/). Could this be the cause of the problem? In landscape what were horizontal gestures become vertical? If so is there a workaround?

Any ideas? Thanks.

Hammer = require "hammerjs"

@body = new Hammer document.body

@body.on "panend", (e) =>

    alert "panned!"

    e.preventDefault()

    if e.direction is Hammer.DIRECTION_LEFT

        # open the menu
Snowman
  • 1,160
  • 1
  • 8
  • 24

0 Answers0