Mouse Wheel Programming _javascript skills

Source: Internet
Author: User
Didn't notice the wheel before, see here is an article saying this: http://www.javascriptsearch.com/guides/Advanced/articles/JSMouseScrolling.html

I turned it over. If it is in practical application, sometimes it is quite useful. The main is to get the wheel is to roll up or down.

The code for the annotation

function handle (Delta) {
if (Delta < 0)
...;
Else
...;
}

/** Event Handle
*/
Function Wheel (event) {
var delta = 0;
if (!event)/* for IE. */
event = window.event;
if (Event.wheeldelta) {/* ie or opera. */
Delta = event.wheeldelta/120;
/** in Opera9, event handling differs from IE
*/
if (Window.opera)
Delta =-delta;
else if (event.detail) {/** compatible with Mozilla. */
/** in Mozilla, sign of Delta are different than in IE.
* Also, Delta is multiple of 3.
*/
Delta =-EVENT.DETAIL/3;
}
/** Trigger if increment is not equal to 0
* Main function for the test wheel to roll up or down
*/
if (Delta)
Handle (delta);
}

/** Initialization * *
if (Window.addeventlistener)
/** Mozilla's DOM-based wheel event **/
Window.addeventlistener (' Dommousescroll ', wheel, false);
/** Ie/opera. */
Window.onmousewheel = Document.onmousewheel = wheel;

In the code above, the code in the handler function is what you write, it has a parameter-delta, in fact, it's just a code mouse that is rolling up or rolling down at the moment. As shown below,
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <ptml xmlns= "http:// Www.w3.org/1999/xhtml "> <pead> <title> mousewheel delta-http://www.never-online.net </title> <meta http-equiv= "Imagetoolbar" content= "no"/> <meta name= "Author" content= "Never-online, BlueDestiny"/> <meta name= "keywords" content= "never modules, Mozilla CSS, C #,. NET, Refercence, Bluedestiny, Never-online"/> <meta name= "description" content= "Bluedestiny, Never-online"/> <meta name= "title" Content= "-http://www.neve R-online.net "/> <meta name=" creator.name "content=" Never-online bluedestiny "/>" <style "type= text/css" Media= "All" title= "Default" > </style> <script type= "Text/javascript" >//<! [cdata[function handle (delta) {var s = Delta + ":"; if (Delta < 0) s + = "down"; Else s + = "up"; document.getElementById (' Delta '). InnerHTML = S; Function Wheel (event) {var delta = 0; if (!event) event = window.event; if (event.wheeldelta) {delta = event.wheeldelta/120; if (window.opera) delta =-delta; else if (event.detail) {delta =-EVENT.DETAIL/3; if (delta) handle (delta); }/* Initialization code. */if (Window.addeventlistener) window.addeventlistener (' Dommousescroll ', wheel, false); Window.onmousewheel = Document.onmousewheel = wheel; ]]> </script> <body id= "www.never-online.net" > <div id= "Delta" >scroll mouse wheel to Del Ta here.</div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.