2011-11-29 42 views
2

我正在寻找jQuery的HTML滚动插件,将在移动设备上刷卡导航,也将在桌面上工作。寻找jQuery项目滚动插件移动

基本上我需要使用滑动手势来旋转新闻,就像在iPad上IMDB应用程序一样,只是在浏览器中。

这里是它的截图: touch scroller IMDB

在寻找,我发现iScroll和煎茶触摸脚本,但他们太“胖”。

任何人都可以推荐这样的东西?

谢谢。

UPD:刚刚在codecanyon上找到了very cool carousel,正是我所需要的。可悲的是它是商业的。

回答

2

您需要使用touchstarttouchmove事件(还有一个touchend事件,但在这种情况下不需要),它们在某种意义上与鼠标事件的工作方式相同。

以下是一个概念示例,因为我以前从未亲自使用过它们,但它应该是相当重要的。

var startX = 0, startY = 0; 

$('.selector.').bind('touchstart', function(event) { 
    startX = event.touches[0].pageX; 
    startY = event.touches[0].pageY; 
}); 

$('.selector.').bind('touchmove', function(event) { 
    endX = event.touches[0].pageX; 
    endY = event.touches[0].pageY; 

    if (startX - 100 < endX) 
    { 
     // SWIPE LEFT CODE HERE 

     // The startX - 100 is to give some leeway for the user, they have to 
     // move there finger at least 100 pixel difference to the left to trigger 
    } 
    elseif (endX > startX + 100) 
    { 
     // SWIPE RIGHT CODE HERE 

     // The startX + 100 is to give some leeway for the user, they have to 
     // move there finger at least 100 pixel different to the right to trigger 
    } 
}); 

的基本概念是你有一个touchstart事件和日志他们在开始位置和touchmove事件,以确定它们的刷卡哪种方式,如果x是下他们离开刷卡,X高于右,y上升然后y下降。

这看起来像一个很好的资源检出http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

+0

非常感谢您的帮助! – Marvin3