Home > Web Front-end > JS Tutorial > js capture mouse wheel event code_javascript skills

js capture mouse wheel event code_javascript skills

WBOY
Release: 2016-05-16 17:08:44
Original
1161 people have browsed it

I saw a written test question for a senior front-end interview at Renren before.

requires handwritten code. One of the questions is to make a picture display

Similar to the small thumbnail at the bottom of the Baidu picture. Display bar

Then ask for a mouse wheel to make it larger and smaller

I really don’t know how to do this, I looked for information on the Internet

I found that it can be done Capture the onmousewheel event

and then determine whether to roll forward or backward based on the positive or negative value of event.wheelDelta

I just wrote a small example and captured the keyboard keys by the way, which is not very beautiful. There is no line break

Because it is made with textNode and the html code cannot be added

Speaking of which, can this method be used to prevent xss injection?

Copy code The code is as follows:



Copy code The code is as follows:

function showKey(){
if(event.wheelDelta){

Copy code The code is as follows :

// Positive 120 means forward roll and negative 120 means backward 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();
}
}

It also happened to use the textNode element from the advanced design I just saw today. A

method of merging multiple textNodes
Copy the code The code is as follows:

normalize();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template