2

我正在尝试将一些 iPhone 样式的滚动惯性添加到只能在 iPad 上查看的网页。

我的滚动在一个方向(scrollLeft)上工作,但它在另一个方向上不起作用。这是一个非常简单的功能:

function onTouchEnd(event){
                event.preventDefault();
                inertia = (oldMoveX - touchMoveX);
                
                // Inertia Stuff
                if( Math.abs(inertia) > 10 ){

                    $("#feedback").html(inertia);
                    
                    $("#container").animate({
                        'scrollLeft': $("#container").scrollLeft() + (inertia * 10)
                    }, inertia * 20);
                    
                }else{
                    
                    $("#feedback").html("No Inertia");
                    
                }
                
            }

我已经将它绑定到touchend身体上的事件。惯性是触摸结束时旧 moveX 位置与最新 moveX 位置之间的差异。

然后我尝试为scrollLeft包含一堆缩略图的 div 的属性设置动画。正如我所说,这在向左滚动时有效,但在向右滚动时无效。

有任何想法吗?

4

1 回答 1

4

“animate(...)”的第二个参数是持续时间,它不能是负数。

尝试:

...
$("#container").animate({
      'scrollLeft': $("#container").scrollLeft() + (inertia * 10)
   }, Math.abs(inertia * 20));
...
于 2010-05-02T09:17:43.840 回答