Js Code for capturing mouse wheel events
This article describes how to use js to capture scroll wheel events. The principle is very simple. For more information, see
Previously, I saw my questions for an Advanced Front-end interview with Renren.
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:
<Body onkeydown = "showKey ()" onmousewheel = "showKey ()">
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 ();