How to specify how many pixels scroll moves on each step?

后端 未结 2 1206
走了就别回头了
走了就别回头了 2020-12-09 23:33

When I use mouse wheel to scroll content in div I want it to scroll by e.g., 30px each step or each mouse wheel tick w/e is the best solution.

2条回答
  •  再見小時候
    2020-12-10 00:19

    There's big problems in implementing mousewheel details yourself, since there is (AFAIK) three different behaviours that the browsers are currently doing. Everything but Firefox currently supports mousewheel event, which passes a wheelDelta parameter of 120 per "click". Firefox has DOMMouseScroll event, that will pass a detail parameter of 3 (I think) per "click", and in the opposite direction. Apple devices have a much more granular resolution, and have a deceleration to them; so Webkit browsers give also delta in the two axes, and there are no "clicks" on a trackpad two-fingered scroll. Finally, DOM Level 3 Events draft standard will define a "click" being (I think) 1, and provide a possibility of three axes; so you need to future-proof your code. So implementing your own wheel handler is kind of a pain (I know since I am now implementing zooming for my SVG app using the mousewheel).

    You can consult Javascript: The Definitive Guide, chapter 17.6 Mousewheel Events, for more details.

提交回复
热议问题