当前位置:网站首页>[move pictures up, down, left and right through the keyboard in JS]
[move pictures up, down, left and right through the keyboard in JS]
2022-07-05 03:33:00 【renrenrenrenqq】
js Move pictures up, down, left and right through the keyboard
The first method
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
</style>
<body>
<img style="left:0px" src="./html-01/images/ house .png" alt="">
<script>
let img=document.querySelector('img')
document.onkeyup = function(event){
if (event.keyCode==37) {
img.style.left = img.offsetLeft-20+"px";
}else if (event.keyCode==38){
img.style.top = img.offsetTop-20+"px";
}else if (event.keyCode==39){
img.style.left = img.offsetLeft+20+"px";
}else if (event.keyCode==40){
img.style.top = img.offsetTop+20+"px";
}
} -->
<!-- </script>
</body> -->
<!-- </html>
The second method ,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
img{
position: absolute;
display: none;
transition: display 2s;
}
</style>
<body>
<img style="left:0px;top: 0px;" src="./html-01/images/ house .png" alt=""> -->
<!-- <script>
document.onkeyup=function(event){
console.dir(event.keyCode)
if(event.keyCode==39){
let img=document.querySelector('img')
let currentLeft=img.style.left;
let index=currentLeft.lastIndexOf('px')
currentLeft=currentLeft.substring(0,index)
img.style.left=(parseInt(currentLeft)+30)+'px'}
else if(event.keyCode==40){
let img=document.querySelector('img')
let currenttop=img.style.top;
let index=currenttop.lastIndexOf('px')
currenttop=currenttop.substring(0,index)
img.style.top=(parseInt(currenttop)+30)+'px'
}
else if(event.keyCode==37){
let img=document.querySelector('img')
let currentLeft=img.style.left;
let index=currentLeft.lastIndexOf('px')
currentLeft=currentLeft.substring(0,index)
img.style.left=(parseInt(currentLeft)-30)+'px'
} else if(event.keyCode==38){
let img=document.querySelector('img')
let currenttop=img.style.top;
let index=currenttop.lastIndexOf('px')
currenttop=currenttop.substring(0,index)
img.style.top=(parseInt(currenttop)-30)+'px'
}
} -->
<!-- </script> -->
边栏推荐
- Flume配置4——自定义MYSQLSource
- 端口,域名,协议。
- Basic knowledge of tuples
- When sqlacodegen generates a model, how to solve the problem that the password contains special characters?
- Azkaban overview
- Anchor free series network yolox source code line by line explanation four (a total of ten, ensure line by line explanation, after reading, you can change the network at will, not just as a participan
- [groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
- [learning notes] month end operation -gr/ir reorganization
- Une question est de savoir si Flink SQL CDC peut définir le parallélisme. Si le parallélisme est supérieur à 1, il y aura un problème d'ordre?
- [105] Baidu brain map - Online mind mapping tool
猜你喜欢
Utilisation simple de devtools
Redis6-01nosql database
Azkaban installation and deployment
[groovy] string (string injection function | asBoolean | execute | minus)
Mongodb common commands
Pat grade a 1119 pre- and post order traversals (30 points)
Easy processing of ten-year futures and stock market data -- Application of tdengine in Tongxinyuan fund
Leetcode42. connect rainwater
Subversive cognition: what does SRE do?
Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation
随机推荐
Comparison of advantages and disadvantages between platform entry and independent deployment
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time
Pat grade a 1119 pre- and post order traversals (30 points)
Huawei MPLS experiment
端口,域名,协议。
Share the newly released web application development framework based on blazor Technology
Sqoop命令
2.常见的请求方法
NPM introduction link symbolic link
Idea inheritance relationship
[groovy] string (string splicing | multi line string)
Breaking the information cocoon - my method of actively obtaining information - 3
Monitoring web performance with performance
单项框 复选框
Machine learning experiment report 1 - linear model, decision tree, neural network part
Share the newly released web application development framework based on blazor Technology
有个疑问 flink sql cdc 的话可以设置并行度么, 并行度大于1会有顺序问题吧?
2021 Li Hongyi machine learning (1): basic concepts
Flume配置4——自定义MYSQLSource