确定用户是否使用鼠标滚轮或滚动条或键盘滚动

确定用户是否使用鼠标滚轮或滚动条或键盘滚动

本文介绍了Javascript / Jquery:确定用户是否使用鼠标滚轮或滚动条或键盘滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让用户界面工作,如果他们使用鼠标滚轮,我需要让它滚动一个方向,如果他们使用滚动条,我需要另一种方式,如果他们使用滚动条,则需要另一种方式滚动键盘。我相信滚轮和滚动条都充当鼠标事件,但是当点击滚动条时我无法使javascript工作。

I'm trying to get a user interface to work, and I need to have it scroll one way if they are using the mouse wheel, and another way if they are using the scrollbar, and another way if they are using a keyboard. I believe scroll wheel and the scroll bar both act as mouse events, but I haven't been able to get javascript to work when clicking on the scrollbar.

推荐答案

滚动条上的鼠标事件在浏览器之间差别很大,并不是您可以信赖的。我做了一些测试,这就是我发现的:

Mouse events over the scrollbar vary widely between browsers and aren't something you can rely on. I did a few tests and here's what I found:


  • Firefox在滚动条上正确地触发所有事件(鼠标按下,移动和向上),即使在拖动栏时也是如此。

  • IE6会将鼠标向下但不向上,只有当拖动栏时才会触发事件。

  • Chrome(因此我假设Safari也会)触发鼠标按下事件。

  • Firefox fires all events (mouse down, move and up) correctly over the scrollbar, even when dragging the bar.
  • IE6 fires mouse down but not up, and fires move events only when not dragging the bar.
  • Chrome (hence I assume Safari too) fires only mouse down events.

我应该补充一点,我没有看到你想要做你所描述的任何情况,即以不同的方式做出滚动的反应。

I should add that I don't see any situation where you would want to do what you describe, i.e. react in different ways to scrolling.

这篇关于Javascript / Jquery:确定用户是否使用鼠标滚轮或滚动条或键盘滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:37