1<body>2<div id= "W" >3<div class= "n" > Press the UP key to move up </div>4<div class= "n" > Press the key to move down </div>5<div class= "n" > Left click to move </div>6<div class= "n" > right-click to move right </div>7<div class= "n" >ctrl+ keyboard key to zoom in </div>8<div class= "n" >ctrl+ keyboard down button to zoom out </div>9<div class= "n" >ctrl+ keyboard keys can be randomly changed color </div>Ten<div id= "box" style= "Width:100px;height:100px;background-color: #ff0;p osition:absolute;left:100px;top:100px; Z-index:-1 "></div> One</div> A<script> - varbox = document.getElementById (' box '); -Document.body.addEventListener (' KeyDown ',function(e) { the Switch(e.keycode) { - Case37: - if(e.ctrlkey) { -Box.style.backgroundColor = ' # ' + (Math.random (). toString ()). substr (-6); +}Else { -Box.style.left = parseint (box.style.left)-6 + ' px '; + } A Break; at Case39: - if(e.ctrlkey) { -Box.style.backgroundColor = ' # ' + (Math.random (). toString ()). substr (-6); -}Else { -Box.style.left = parseint (box.style.left) + 6 + ' px '; - } in Break; - Case38: toBox.style.top = parseint (box.style.top)-6 + ' px '; + if(e.ctrlkey) { -Box.style.width = parseint (box.style.width) + 4 + ' px '; theBox.style.left = parseint (box.style.left)-2 + ' px '; *Box.style.height = parseint (box.style.height) + 4 + ' px '; $Box.style.top = parseint (box.style.top) + 4 + ' px ';Panax Notoginseng } - Break; the Case40: +Box.style.top = parseint (box.style.top) + 6 + ' px '; A if(e.ctrlkey) { theBox.style.width = parseint (box.style.width)-4 + ' px '; +Box.style.left = parseint (box.style.left) + 2 + ' px '; -Box.style.height = parseint (box.style.height)-4 + ' px '; $Box.style.top = parseint (box.style.top)-4 + ' px '; $ } - Break; - } the Console.log (e.keycode); - })Wuyi</script> the</body>
The page has a div 100*100 color yellow press the keyboard and the left and right keys can operate div Mobile CTRL + keyboard up and down can zoom out CTRL + keyboard around keys can be randomly changed color