Solved

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

Posted on 2005-02-05
5
3,228 Views
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!)

Thanks!
0
Comment
Question by:sleepybear
  • 2
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 13232541
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13232550
0
 
LVL 10

Expert Comment

by:ljo8877
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");
     }
}
 
0
 

Author Comment

by:sleepybear
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.

Thanks!
0
 
LVL 10

Accepted Solution

by:
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"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<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;
         }
     }
}
-->
</script>

</head>

<body>
<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>
          </select>
        <input type="text" id="msge" size="15">
</form>
</body>
</html>
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Viewers will learn how to use the Hootsuite Dashboard.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

713 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