Triggering Hammer.js drag/slide behavior on mouse click

若如初见. 提交于 2019-12-23 01:19:21

问题


I'm using Hammer.js to allow for dragging between panes. I also want to allow an alternate action where there's also a "Next" button you can click on (with a mouse) or touch (on touchscreen), that will automatically animate a slide to the next screen.

Imagine the Hammer.js Carousel demo with a "next" button in the middle of the page. When you click, it acts as if you did a slideleft to take you to the next pane.

I figured I should be able to trigger with something like:

var hammertime = Hammer('button.next-button').on("tap", function(event) {
    self.next();        
});

That only seems to put my mouse into drag mode, rather than executing the whole animation.


回答1:


I've run into the same problem. self.next() will evidently not work as the next function is not defined in the self element.

You need to initizalize a new carousel instance, and then call the showPane(index) method:

      var hammertime = Hammer(doubletapRegion).on("tap", function (event) {
          console.log(event);
          var carousel = new Carousel("#carousel");
          carousel.init();
          carousel.showPane(1);
      });

This code will move the the second pane (index = 1). You can of course put a variable there.



来源:https://stackoverflow.com/questions/15582578/triggering-hammer-js-drag-slide-behavior-on-mouse-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!