【问题标题】:Redirect on swipe with hammer.js使用hammer.js在滑动时重定向
【发布时间】:2017-09-06 09:02:59
【问题描述】:

我需要帮助。我在 ul 中有两个链接。

<ul class="group switcher">
    <li><a href="/" id="next"><i class="fa fa-list-ul" aria-hidden="true"></i></a></li>
    <li><a href="news-table.html" id="previous"><i class="fa fa-th-large" aria-hidden="true"></i></a></li>
</ul>

当我向右滑动#next我想重定向到 news-table.html。我使用 Hammer.js。谢谢!

【问题讨论】:

  • 你也用jQuery吗?
  • 我无法使用 jquery mobile。
  • 这是您想要的答案吗?如果不是,请告诉我,如果是,请检查作为答案...

标签: javascript jquery hammer


【解决方案1】:
var options = { /* your options*/};

$('#next').hammer(options).bind("swiperight", function() {
    var href = $(this).attr('href');
    $(window).location.replace(href);
});

只能通过阅读文档来回答。可能需要对您的代码进行一些调整...

【讨论】:

  • 我能问你,选项应该是什么?谢谢
  • 我不知道hammerjs,从未使用过它。但似乎您甚至不必传递选项对象。所以$('#next').hammer().bind(...) 应该已经可以工作了。在选项对象中,如果需要,您只需传递hammerjs-options。
  • 抱歉,我刚才已经测试过了。但仍然显示此错误:Uncaught TypeError: $(...).hammer is not a function at swipe-button.js:2。我添加了一个 jquery.hammer.js 插件,但仍然无法正常工作。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多