JS Capture Mouse Wheel event code

Source: Internet
Author: User

  This article describes how to use JS to capture the mouse wheel event, the principle is very simple, interested friends can refer to the following

Before seeing a senior front-end interview for Renren     requirements Handwriting code, which has a problem is to do a photo show     similar to Baidu pictures the bottom of the small thumbnail thumbnails that display bar     And then ask for a mouse wheel rolling larger and smaller requirements     This I really don't know how to do, look for information on the Internet     Discovery can capture OnMouseWheel events     Then according to the Event.wheeldelta value of the positive and negative to determine whether the roll forward or after the roll     casually wrote a small example, by the way to capture the keyboard keys, not very beautiful no line     because of the textnode do, add the HTML code     Is it possible to prevent XSS injection in this way?       Code as follows: <body onkeydown= "Showkey ()" Onmousewheel= "Showkey ()" >    code as follows: function Showkey () {  if (event.wheeldelta) {    code as follows://positive 120 for roll forward minus 120 for roll   var textnode = document.createTextNode (event.wheeldelta+ "");  Document.body.appendChild (textnode);  Document.body.normalize (); }  if (event.keycode)   {  var textnode = document.createTextNode ( Event.keycode+ "");  Document.body.appendChild (textnode);  document.body.normalize (); } }     One of the textnode elements that we just saw today in the advanced design.     Merging multiple Textnode the     code is as follows: Normalize ();  

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.