Javascript 在javascript中模拟用鼠标滑动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7894458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simulate swipe with mouse in javascript
提问by gabitzish
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?
我正在尝试制作一个可以在移动设备上使用滑动导航的图像旋转器。我也在尝试使相同的旋转器在 PC 浏览器上工作,但能够使用鼠标拖动来模拟滑动。有什么好主意吗?
采纳答案by gilly3
You'll want to handle onmousedown
, onmousemove
, and onmouseup
events, keeping track of the mouse position and manipulating your image rotator accordingly.
您需要处理onmousedown
、onmousemove
和onmouseup
事件,跟踪鼠标位置并相应地操作图像旋转器。
回答by FreePender
回答by Jasper
I believe you are looking for this answer: Standalone jQuery "touch" method?
我相信您正在寻找这个答案: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).
接受的答案具有实现向左/向右滑动支持的代码,下方的另一个答案具有指向执行类似任务的插件的链接:http: //www.netcu.de/jquery-touchwipe-iphone-ipad-library(这个插件允许检测四个方向的滑动)。
回答by Jorik
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.
当您使用 Hammer.js 时,您还支持触摸/鼠标和指针事件。这适用于 chromebook pixel 和 windows8 等触摸屏笔记本电脑。那里的大多数图书馆还不支持这些。
回答by FreePender
I ended up using iDangerous iSwiper, which met all my needs and is (IMO) very excellent.
我最终使用了iDangerous iSwiper,它满足了我的所有需求并且(IMO)非常出色。