当前位置:网站首页>小女孩行走
小女孩行走
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
边栏推荐
- 请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨
- 应纳税所得额
- Restore binary tree (25 points)
- PCTP考试经验分享
- Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
- Idea import commons-logging-1.2 Jar package
- Go language self-study series | golang method
- Please arrange star trek in advance to break through the new playing method of chain tour, and the market heat continues to rise
- How much inventory recording does the intelligent system of external call system of okcc call center need?
- Valgrind et kcachegrind utilisent l'analyse d'exécution
猜你喜欢
经典题目刷一刷
valgrind和kcachegrind使用運行分析
Valgrind et kcachegrind utilisent l'analyse d'exécution
ONEFLOW learning notes: from functor to opexprinter
OneFlow學習筆記:從Functor到OpExprInterpreter
Chris LATTNER, father of llvm: the golden age of compilers
Introduction to GUI programming swing
L2-3 romantic silhouette (25 points)
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
L2-3 浪漫侧影 (25 分)
随机推荐
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
Open services in the bottom bar of idea
L2-023 graph coloring problem (25 points) (graph traversal)
MySQL小練習(僅適合初學者,非初學者勿進)
PCTP考试经验分享
MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
调包求得每个样本的k个邻居
【58】最后一个单词的长度【LeetCode】
Go language self-study series | golang structure as function parameter
Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
Test your machine learning pipeline
STM32 uses Hal library. The overall structure and function principle are introduced
L2-024 tribe (25 points) (and check the collection)
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
Automatic differentiation and higher order derivative in deep learning framework
完全二叉搜索树 (30 分)
Arbre de dépendance de l'emballage des ressources
Rembg split mask
Download and install bashdb
uni-app和微信小程序中的getCurrentPages()