当前位置:网站首页>小女孩行走
小女孩行走
2022-04-23 09:01:00 【一个博客】
小女孩行走
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>小女孩找妈妈</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
position: absolute;
background-image: url('./image/xnh.png');
height: 106px;
width: 82px;
background-position:0px -212px;
left: 0;
}
</style>
</head>
<body>
<script src="./underscore-min.js"></script>
<script>
//创建构造函数
function Gril(){
//创建一个div节点
this.dom=document.createElement("div");
document.body.appendChild(this.dom); //div节点添加到body中
var self=this; //保存当前的this指向
this.x=0; //定义从左往右走的步伐
this.speed=_.random(1,10); //控制步伐速度
this.state=0; //定义图片的宽度的移动
this.ismove=true; //小女孩在行走
this.dom.onclick=function(){ //图片点击后的动作
if(self.ismove){ //判断是否在行走,如果是就执行,if后的语句
clearInterval(self.timer); //清除定时器
self.ismove=false; //小女孩没在行走
}
else{ //如果没在行走,就执行
self.move(); //开启定时器
self.ismove=true;
}
}
this.move() //默认在行走
}
Gril.prototype.move=function(){ //创建原型对象
var self=this; //保存当前的this指向
this.timer=setInterval(function(){ //把定时器保存在timer属性中
self.state++; //把图片的移动自增
self.x+=_.random(1,10); //随机步伐速度
if (self.state>=8) { //if判断图片是第几张,如果大于最后一张,从第一张开始
self.state=0
}
self.dom.style.backgroundPosition=-82*self.state+"px -"+self.state+"px";//图片的位置
self.dom.style.left=self.x+"px"; //向左边行走的速度
}, this.speed*100);
}
//for循环动态创建10图片
for (var i = 0; i < 10; i++) {
new Gril();
}
</script>
</body>
</html>
版权声明
本文为[一个博客]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45784582/article/details/106335814
边栏推荐
- LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
- Complete binary search tree (30 points)
- Error: cannot find or load main class
- GUI编程简介 swing
- Bk3633 specification
- valgrind和kcachegrind使用運行分析
- Go language self-study series | golang structure pointer
- Output first order traversal according to second order and middle order traversal (25 points)
- Use of Arthas in JVM tools
- Get the absolute path of the class according to the bytecode
猜你喜欢
Brush classic topics
Strength comparison vulnerability of PHP based on hash algorithm
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
Use of Arthas in JVM tools
LLVM之父Chris Lattner:编译器的黄金时代
L2-3 浪漫侧影 (25 分)
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
L2-022 重排链表 (25 分)(map+结构体模拟)
Test your machine learning pipeline
随机推荐
Go语言自学系列 | golang方法
How to read excel table to database
Harbor enterprise image management system
BK3633 规格书
L2-024 tribe (25 points) (and check the collection)
Illegal character in scheme name at index 0:
MySQL小练习(仅适合初学者,非初学者勿进)
还原二叉树 (25 分)
Introduction to matlab
What is augmented reality technology? Where can it be used?
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
关于堆的判断 (25 分) 两种插入方式
Introduction to GUI programming swing
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
K210 learning notes (II) serial communication between k210 and stm32
Research purpose, construction goal, construction significance, technological innovation, technological effect
Get the absolute path of the class according to the bytecode
Withholding agent
Valgrind et kcachegrind utilisent l'analyse d'exécution
After a circle, I sorted out this set of interview questions..