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

Posted on 2005-02-05
Last Modified: 2013-11-15
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!)

Question by:sleepybear
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 63

Expert Comment

ID: 13232541
LVL 63

Expert Comment

ID: 13232550
LVL 10

Expert Comment

ID: 13233719
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");

Author Comment

ID: 13236734
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.

LVL 10

Accepted Solution

ljo8877 earned 500 total points
ID: 13237131
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">

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question