<分区>
我正在寻找 jQuery HTML 滚动器插件,它可以在移动设备上进行滑动导航,也可以在桌面上运行。
基本上我需要使用滑动手势来旋转新闻,就像在 iPad IMDB 应用程序上一样,只是在浏览器中。
截图如下:
在搜索时我找到了 iScroll 和 Sencha Touch 脚本,但它们太“胖”了。
谁能推荐这样的东西?
谢谢。
更新:刚找到very cool carousel在 codecanyon 上,正是我所需要的。可惜是商用的。
<分区>
我正在寻找 jQuery HTML 滚动器插件,它可以在移动设备上进行滑动导航,也可以在桌面上运行。
基本上我需要使用滑动手势来旋转新闻,就像在 iPad IMDB 应用程序上一样,只是在浏览器中。
截图如下:
在搜索时我找到了 iScroll 和 Sencha Touch 脚本,但它们太“胖”了。
谁能推荐这样的东西?
谢谢。
更新:刚找到very cool carousel在 codecanyon 上,正是我所需要的。可惜是商用的。
最佳答案
您需要使用 touchstart
和 touchmove
事件(还有一个 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
关于javascript - 寻找适用于移动设备的 jQuery 元素滚动插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312341/