在javascript中模拟鼠标滑动
我正在尝试制作一个可在移动设备上使用滑动进行导航的图像旋转器。我还尝试使相同的旋转器在 PC 浏览器上工作,但能够使用鼠标拖动来模拟滑动。 有什么好主意吗?
I'm trying to make an image rotator that works on mobile devices using swipe for navigation. I'm also trying to make the same rotator to work on PC browsers but to be able to use the mouse drag to simulate swipe.
Any good ideeas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我已经研究了其中的大部分...我建议
研究Hammer.Js
从我的一点点 我已经看到,它支持桌面和移动设备滑动,演示给我留下了深刻的印象。
I've looked into most of these... I'd recommend looking into
Hammer.Js
From what little I've seen, it has support for both desktop and mobile swiping and I was impressed with the demos.
您需要处理
onmousedown
、onmousemove
和onmouseup
事件,跟踪鼠标位置并相应地操作图像旋转器。You'll want to handle
onmousedown
,onmousemove
, andonmouseup
events, keeping track of the mouse position and manipulating your image rotator accordingly.我相信您正在寻找这个答案: 独立 jQuery“触摸”方法?
接受的答案有实现向左/向右滑动支持的代码,下面的另一个答案有一个指向执行类似任务的插件的链接: http://www.netcu.de/jquery-touchwipe-iphone-ipad-library(该插件允许检测四个方向的滑动)。
I believe you are looking for this answer: Standalone jQuery "touch" method?
The accepted answer has code to implement swipe left/right support and another answer lower down has a link to a plugin that does a similar task: http://www.netcu.de/jquery-touchwipe-iphone-ipad-library (this plugin allows detection of swipes in four directions).
当您使用 Hammer.js 时,您还支持触摸/鼠标和指针事件。这适用于 chromebook Pixel 和 windows8 等触摸屏笔记本电脑。大多数图书馆还不支持这些。
When you use Hammer.js, you also have support for touch/mouse and pointer events. This for touch screen laptops like the chromebook pixel and windows8. Most of the libraries out there dont support those yet.
我最终使用了 iDangerous iSwiper,它满足了我的所有需求,并且(IMO)非常出色。
I ended up using iDangerous iSwiper, which met all my needs and is (IMO) very excellent.