当前位置:网站首页>小女孩行走
小女孩行走
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
边栏推荐
- [58] length of the last word [leetcode]
- 微信:获取单个标签所有人
- MySQL小练习(仅适合初学者,非初学者勿进)
- Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
- 使用flask和h5搭建网站/应用的简要步骤
- Introduction to matlab
- Four pictures to understand some basic usage of Matplotlib
- 完全二叉搜索树 (30 分)
- 资源打包关系依赖树
- Strength comparison vulnerability of PHP based on hash algorithm
猜你喜欢
Consensus Token:web3. 0 super entrance of ecological flow
Non duplicate data values of two MySQL query tables
Idea import commons-logging-1.2 Jar package
valgrind和kcachegrind使用运行分析
Download and install bashdb
Valgrind et kcachegrind utilisent l'analyse d'exécution
[58] length of the last word [leetcode]
Study notes of deep learning (8)
Enterprise wechat application authorization / silent login
DJ music management software pioneer DJ rekordbox
随机推荐
Reference passing 1
Error: cannot find or load main class
How to read excel table to database
Latex mathematical formula
Single chip microcomputer nixie tube stopwatch
Go language self-study series | golang method
错误: 找不到或无法加载主类
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
[boutique] using dynamic agent to realize unified transaction management II
微信:获取单个标签所有人
Flink同时读取mysql与pgsql程序会卡住且没有日志
搜索树判断 (25 分)
mycat配置
Go语言自学系列 | golang方法
[indexof] [lastIndexOf] [split] [substring] usage details
Harbor enterprise image management system
valgrind和kcachegrind使用运行分析
Notes on xctf questions
关于堆的判断 (25 分) 两种插入方式
Test your machine learning pipeline