Search code examples
onsen-uigesturesmonaca

onsen-ui gestures not working


I need to implement a menu with the exact same looks as onsen sliding-menu,but that slides from top. I was thinking to use onsen gestures to be able to drag the menu, but the gestures sample provided in the onsen guide does not work. Am I missing something?

  <ons-gesture-detector>
    <div id="detect-area" style="width: 300px; height: 300px;background-color:blue;">
      Swipe Here
    </div>
  </ons-gesture-detector>

  <script>
    alert("in");
    $(document).on('swipeleft', '#detect-area', function() {
      alert("swipe");
    })
  </script>

Solution

  • Try this, it should work. Don't forget to add jquery first.

    <ons-gesture-detector style="height: 300px; margin: 50px 50px;">
        <div id="hoge" style="border: 1px solid #ccc; background-color: #f9f9f9; width: 100%; height: 300px; line-height: 300px; text-align: center; color: #999;">
            ...
        </div>
    </ons-gesture-detector>

    <script>
        var eventName = 
          'drag dragleft dragright dragup dragdown hold release swipe swipeleft swiperight ' +
          'swipeup swipedown tap doubletap touch transform pinch pinchin pinchout rotate';
    
        $(document).on(eventName, '#hoge', function(event) {
          if (event.type !== 'release') {
            $(this).text(event.type);
          }
        });
     </script>