Detecting mousewheel on the x-axis (left and right) with Javascript

后端 未结 5 1944
面向向阳花
面向向阳花 2020-12-13 10:43

I know it\'s possible to detect up and down e.g.

    function handle(delta) {
    if (delta < 0) {
        alert(\'down\');
} else {
    alert(\'up\');
           


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 11:06

    Check the accepted answer for more links and info.

    Bubbling scroll/mousewheel event

    event.detail specifies the number of "ticks" that the mouse wheel moved.

    Positive values mean down/right", negative up/left.

    event.axis specifies the axis of the scroll gesture (horizontal or vertical). This attribute was added in Firefox 3.5

    Chrome implements the same behavior as IE AFAIK. In IE and Chrome: use e.wheelDeltaX and e.wheelDeltaY

提交回复
热议问题