制作老虎机小游戏
作者:互联网
老虎机小游戏
一、代码
1.老虎机代码
代码如下(示例):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#b{
background: url("image/老虎机.jpg.png");
z-index: -1;
width: 335px;
height: 326px;
position: absolute;
margin-top: 200px;
margin-left: 400px;
}
#btn1{
}
</style>
</head>
<body>
<div id=>
<div id="a" style="width: 50px;
height: 50px;
border: 2px solid #ff0000;
position: absolute;
margin-top: 215px;
margin-left: 425px;">
</div>
<div id="b"></div>
<div>
<button id="btn1" onclick="start2()">开始</button>
<button id="btn2" onclick="stop2()">停止</button>
</div>
</div>
</body>
<script>
let a = document.getElementById("a");
let ii=0;
let w=425;
let h=215;
function start2(){
ss = setInterval(show,100);
}
function stop2() {
clearInterval(ss)
}
function show(){
++ii;
i=ii%21;
if (i<6) {
w += 48;
a.style.marginLeft = w + "px";
}else if (i<=10){
h+=49;
a.style.marginLeft = w + "px";
a.style.marginTop = h + "px";
}else if (i<=15){
w-=48;
a.style.marginLeft = w + "px";
}else if (i<=19){
h-=49;
a.style.marginTop = h + "px";
}else if (i==20){
a.style.marginLeft ="425px";
a.style.marginTop ="215px";
w=425;
h=215;
ii=0;
}
}
</script>
</html>
总结
以上就是制造老虎机小游戏的全部内容,主要利用的是html、css、以及js的技术实现的老虎机小游戏。
标签:style,px,else,marginLeft,小游戏,制作,老虎机 来源: https://blog.csdn.net/StruggleBamboo/article/details/112692064