Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function when the user uses the mouse wheel to scroll up/down in javascript

Tags:

javascript

In HTML I have a table that is used as a grid. Now, I want to attach an event to this table, that when a scroll up/down is triggered, then my ScrollUp/ScrollDown function is called.

like image 318
Stavros Avatar asked Sep 09 '10 13:09

Stavros


People also ask

When I scroll my mouse wheel goes up and down?

Mouse scroll wheel jumps can usually be solved by basic troubleshooting techniques like rebooting the computer, cleaning the mouse components, replacing or recharging the mouse batteries, or checking the wireless connection or USB port. The issue can also be resolved by updating corrupt or outdated drivers.

Which event is called when a mouse wheel scrolls?

The onwheel event occurs when the mouse wheel is rolled up or down over an element. The onwheel event also occurs when the user scrolls or zooms in or out of an element by using a touchpad (like the "mouse" of a laptop).


2 Answers

You need some JS Framework to simply your development and not reinvent the wheel.

Here is examples for Mootools

  1. http://demos.mootools.net/CustomEvents
  2. http://demos111.mootools.net/Mousewheel

And here for JQuery

  1. http://api.jquery.com/scroll/
like image 149
Alex Avatar answered Nov 02 '22 13:11

Alex


If your looking for a cross browser, JavaScript framework independent version then this will do what you need

http://adomas.org/javascript-mouse-wheel/

like image 39
John Doherty Avatar answered Nov 02 '22 12:11

John Doherty