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

Source: Internet
Author: User

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

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.