Is the use of the mouse wheel a measurable event in Javascript or VBscript?

sleepybear used Ask the Experts™
Is the use of the scrolly mouse wheel an event that's
capturable in Javascript... or VBscript?

Mine lets you scroll up and down the page, or if you click it
you can use the mouse itself to scroll.

Is that an event that's detectable somehow?
If so, can you give me an example of how that's done?

(BTW, is there a VBscript section on this site? I couldn't
find it anywhere!)

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Zvonko זְאֵבSystems architect
Top Expert 2006

Zvonko זְאֵבSystems architect
Top Expert 2006


The event object of IE 5.5 and above has a wheelDelta property that indicates the direction of the wheel roll. It is an integer with positive being toward the screen or up and negative away from the screen or down.

if (evt.type == "mousewheel" ) {

      if (window.event && window.event.wheelDelta ) {
           if (window.event.wheelDelta > 0) alert("Wheel rolled up");
           else if (window.event.wheelDelta < 0)alert("Wheel rolled down");
           else alert("Not up or Down");


Sorry ljo8877, but I'm not sure how to call your script example.

Can you place your code in a full html head and body page example
so I can see what you mean? Sorry, but I've just never seen this
done before so I don't know how to plug it in to anything.

I'm sure you can attach or bind a function to the onMouseWheel event in either of the three common ways -- addListener/attachEvent, document.onmousewheel = fxName;, or onmousewheel="fxName();" in a tag. I've chosen the later for this example as a matter of convenience. In this demo a text box will display the direction the mouse wheel is rolled when the mouse is in a dropdown listbox. (I dumped the alerts because they change the focus and you don't get to see the entries scroll.)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>demo capture of mousewheel</title>

<script type="text/javascript">
function getWheel(){
     if (window.event.type == "mousewheel" ) {
          if (window.event && window.event.wheelDelta ) {
                var msge = "";
                if (window.event.wheelDelta > 0) msge = "Wheel rolled up";
                else if (window.event.wheelDelta < 0) msge = "Wheel rolled down";
                else msge = "Not up or Down";

              document.getElementById("msge").value = msge;


<form id="frmEntry" name="frmEntry" method="post" action="_self" onmousewheel="getWheel();" size="3">
          <select id="country2" name="country2" tabindex="2">
          <option value="AFG">Afghanistan</option>
          <option value="ALB">Albania</option>
          <option value="DZA">Algeria</option>
          <option value="ASM">American Samoa</option>
          <option value="AND">Andorra</option>
          <option value="AGO">Angola</option>
          <option value="AIA">Anguilla</option>
          <option value="ATG">Antigua and Barbuda</option>
          <option value="ARG">Argentina</option>
          <option value="ARM">Armenia</option>
          <option value="ABW">Aruba</option>
          <option value="AUS">Australia</option>
          <option value="AUT">Austria</option>
          <option value="AZE">Azerbaijan</option>
          <option value="BHS">Bahamas</option>
          <option value="BHR">Bahrain</option>
          <option value="BGD">Bangladesh</option>
          <option value="BRB">Barbados</option>
          <option value="BLR">Belarus</option>
          <option value="BEL">Belgium</option>
          <option value="BLZ">Belize</option>
          <option value="BEN">Benin</option>
          <option value="BMU">Bermuda</option>
          <option value="BTN">Bhutan</option>
          <option value="BOL">Bolivia</option>
          <option value="BIH">Bosnia and Herzegovina</option>
        <input type="text" id="msge" size="15">

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial