【问题标题】:Hammer JS swipe calendar datesHammer JS 滑动日历日期
【发布时间】:2017-01-18 11:25:21
【问题描述】:

我有锤子 js 和 jquery-hammer 插件,可以处理非常简单的滑动动作。

应该发生的情况是,当我向左滑动时,我有一个日历,其日期可以追溯到一天,而当我向右滑动时,它应该向前一天。在我滑动的那一刻,它会根据我滑动的方向和滑动所用的时间(我猜)跳跃数天。

当我将此功能更改为左右容器上的简单点击事件时,日期按预期每次点击仅提前一天。

event.gesture.preventDefault();

给出“非函数错误”

如何让每次滑动只调用一次此函数?

module.exports = View.extend({
    template: 'bookings/templates/components/body',
    className:'bookings-lists',
    deviceType: App.browser.device.deviceType,
    events: {
        'swipe' : 'swipeMe'
    },
    swipeMe: function(e){
        var that = this;
        container.hammer().on('swipeleft', function(event) {
            event.gesture.preventDefault();
            that.model.pushDateForward();
        }).on('swiperight', function(event) {
            event.gesture.preventDefault();
            that.model.pushDateBackward();
        });
    } });

【问题讨论】:

  • 我设法将 drag_lock_min_distance 更改为 50,因此现在您必须滑动 50px 才能更改日期,这样日期只会更改一次。不理想,因为在手机上是一个大的滑动。欢迎任何其他建议。

标签: jquery-plugins hammer.js


【解决方案1】:

我上面的评论是完全错误的。检查滑动的方向,而不是仅仅依靠内置的“swipeleft”或“swiperight”工作。不再有多个日期更改。

swipeMe: function(e){

        if(e.gesture.direction === 4)
        {
            e.preventDefault();
            this.model.pushDateBackward();
        }
        else if(e.gesture.direction === 2)
        {
            e.preventDefault();
            this.model.pushDateForward();
        }
    },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 2011-11-11
    相关资源
    最近更新 更多