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 ();  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.