本文介绍了Hammer.js跳过“开关"内的“案例"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Hammer更新到v2后,它不再识别手势.它确实触发了"switch(event.type)",但跳过了所有情况.不再支持大小写"吗?

After updating Hammer to v2 it doesn't recognize gestures anymore. It does trigger 'switch(event.type)' but skips all of the cases. Is 'case' not supported anymore?

代码示例:

function handleHammer(event) {
    // disable browser scrolling
    event.preventDefault();

    switch(event.type) {
        case 'tap':
            the_single_post.removeClass('grab');
            var tapPos = (event.gesture.center.pageX) - (element.offset().left);

            if (tapPos > paneWidth/2) {
                hammer.next('easeinout');
            }
            else if (tapPos < paneWidth/2) {
                hammer.prev('easeinout');
            }
            break;

        case 'drag':
            (etc.)
    }
}

推荐答案

Hammer.js 2.0是从头开始重写的,其工作原理完全不同.例如,没有拖动事件,而是支持平移事件.您将不得不更改一些代码才能切换到Hammer.js 2.0

Hammer.js 2.0 is rewritten from scratch and works totally different. For example there is no drag event, instead the pan event is supported. You will have to change quite some code to switch to hammer.js 2.0

这篇关于Hammer.js跳过“开关"内的“案例"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:49