在javascript中用鼠标模拟滑动

时间:2022-06-04 09:06:28

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浏览器上工作,但是能够使用鼠标拖动来模拟滑动。有什么好的想法吗?

5 个解决方案

#1


4  

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事件,跟踪鼠标位置并相应地操纵图像旋转器。

#2


8  

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.

从我看到的很少,它支持桌面和移动刷卡,我对演示印象深刻。

#3


4  

I believe you are looking for this answer: Standalone jQuery "touch" method?

我相信你正在寻找这个答案:独立的jQuery“触摸”方法?

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(this插件允许在四个方向上检测滑动)。

#4


2  

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。那里的大多数图书馆都不支持这些。

#5


2  

I ended up using iDangerous iSwiper, which met all my needs and is (IMO) very excellent.

我最终使用iDangerous iSwiper,它满足了我的所有需求,并且(IMO)非常出色。

#1


4  

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事件,跟踪鼠标位置并相应地操纵图像旋转器。

#2


8  

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.

从我看到的很少,它支持桌面和移动刷卡,我对演示印象深刻。

#3


4  

I believe you are looking for this answer: Standalone jQuery "touch" method?

我相信你正在寻找这个答案:独立的jQuery“触摸”方法?

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(this插件允许在四个方向上检测滑动)。

#4


2  

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。那里的大多数图书馆都不支持这些。

#5


2  

I ended up using iDangerous iSwiper, which met all my needs and is (IMO) very excellent.

我最终使用iDangerous iSwiper,它满足了我的所有需求,并且(IMO)非常出色。