Javascript code for capturing mouse wheel events _ javascript skills

Source: Internet
Author: User
This article describes how to use js to capture the scroll wheel event. The principle is very simple. If you are interested, you can refer to the previous questions for a person's network Advanced Front-end interview.

Handwritten code is required. One of the questions is to present an image.

Display bar similar to the thumbnail at the bottom of Baidu Image

Then, you must have a scroll wheel to become larger and smaller.

I really don't know how to do this. I found some information on the Internet.

Onmousewheel events can be captured.

Then, based on the positive and negative values of event. wheelDelta, determine whether to roll forward or backward.

I just wrote a small example. By the way, I captured the keyboard buttons, which is not very nice and there is no line break.

Because textNode is used, html code cannot be added.

Can this method be used to prevent xss injection?

The Code is as follows:




The Code is as follows:


Function showKey (){
If (event. wheelDelta ){


The Code is as follows:


// Positive 120 indicates roll-forward, negative 120 indicates roll-back
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 ();
}
}


It also happens to use one of the textNode elements in the advanced design.

How to merge multiple textnodes

The Code is as follows:


Normalize ();

Related Article

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.