【问题标题】:get the velocity value of a swipe?获得滑动的速度值?
【发布时间】:2014-09-10 10:22:26
【问题描述】:

hammer.js (http://hammerjs.github.io/recognizer-swipe/) 检查滑动的速度,我想知道如何获取这个值以阻止我的元素#visitContent 的左边距应该有多大并获得更平滑的滑动。

html

    <section id="visits">
            <div id='visitsContent'>
              <div></div>
              <div></div>
              <div></div>
            </div>
        </section> 

Javascript

var visits = document.getElementById('visits');
var mc = new Hammer(visits, {velocity:0.80});

mc.on("swipeleft", function(ev) {
    $('#visitsContent').css({
    marginLeft : '-=200px'
})
});
mc.on("swiperight", function(ev) {
    $('#visitsContent').css({
    marginLeft : '+=200px'
})
});

sass

    #visits
    width: 100%
    padding: 0px
    border-bottom: none
    background-color: $backgroundColorSecond
    margin-bottom: 10px
    margin-left: -20px
    #visitsContent
        div
            width: 180px
            height: 180px
            float: left
            margin-left: 5px
            background-color: green
            color: black
            text-align: center

还有一个小提琴 http://jsfiddle.net/mL911mqn/

【问题讨论】:

    标签: javascript swipe hammer.js


    【解决方案1】:

    从您的 jsfiddle 看来,您现在使用的是平移手势而不是滑动手势。因此,在您的平移事件处理程序中,您应该能够像这样访问拖动速度:

    function panGestureHandler(ev){
        var velocity = ev.gesture.velocity;
        var velocityX = ev.gesture.velocityX;
        var velocityY = ev.gesture.velocityY;
        console.log("horizontal drag speed = " + velocityX);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 2022-06-01
      相关资源
      最近更新 更多