javascript - 寻找适用于移动设备的 jQuery 元素滚动插件

标签 javascript jquery css mobile scroll

<分区>

我正在寻找 jQuery HTML 滚动器插件,它可以在移动设备上进行滑动导航,也可以在桌面上运行。

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

截图如下: touch scroller IMDB

在搜索时我找到了 iScroll 和 Sencha Touch 脚本,但它们太“胖”了。

谁能推荐这样的东西?

谢谢。

更新:刚找到very cool carousel在 codecanyon 上,正是我所需要的。可惜是商用的。

最佳答案

您需要使用 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

关于javascript - 寻找适用于移动设备的 jQuery 元素滚动插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312341/

相关文章:

javascript - 如何在其他域中嵌入 React 组件?

php - 将静态 html 菜单转换为 wordpress 动态菜单,保持样式相同

html - Bootstrap 3 响应式大型菜单

javascript - div 中的背景图像始终显示图像的特定部分(缩放和定位)

javascript - 如果在 Document Ready 功能中不工作

javascript - 从对象数组中删除重复项,但将一个属性保留为数组

javascript - 获取并附加来自 url 的前四张图像

JavaScript 未加载最新提交的数据

php - 两个用户编辑同一个表/资源

Javascript beforesend 函数在所有 "add to cart"按钮上错误显示