js实现Tomcat游戏
2017-05-19 23:17
267 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
body,html{
width:100%;
height:100%;
}
#cat{
position: absolute;
width: 100%;
height: 100%;
}
img{
position: absolute;
width:50px;
}
#cymbal{
left: 5%;
bottom: 40%;
}
#eat{
left: 5%;
bottom:20%
}
#drink{
left: 5%;
bottom: 30%;
}
#fart{right: 5%;bottom: 40%;}
#pie{right: 5%;bottom: 30%;}
#scratch{right: 5%;bottom: 20%;}
</style>
</head>
<body>
<img id="cat" src="img/angry/angry_00.jpg"/>
<!--加载按钮-->
<img id="cymbal" src="img/cymbal/cymbal.png">
<img id="eat" src="img/eat/eat.png">
<img id="drink" src="img/drink/drink.png">
<img id="pie" src="img/pie/pie.png">
<img id="fart" src="img/fart/fart.png">
<img id="scratch" src="img/scratch/scratch.png">
<script>
var timer;
window.onload=function(){
// 点击相应按钮,播放相应图片。动画名称,图片总数
document.getElementById("cymbal").onclick=function(){
startAnimation("cymbal",12);
}
document.getElementById("eat").onclick=function(){
startAnimation("drink",81);
}
document.getElementById("drink").onclick=function(){
startAnimation("eat",40);
}
document.getElementById("fart").onclick=function(){
startAnimation("fart",28);
}
document.getElementById("pie").onclick=function(){
startAnimation("pie",24);
}
document.getElementById("scratch").onclick=function(){
startAnimation("scratch",56);
}
}
//播放动画的方法,动画名称和图片总数
function startAnimation(name,count){
clearInterval(timer);
var index=0;
var img=document.getElementById("cat");
timer=setInterval(function(){
//判断是否可以继续播放
if(++index<count){
img.src=getImageName(name,index);
}else{
//没有可以播放的图片,清楚定时器
clearInterval(timer);
}
},80);
}
//图片路径
//根据动画名和图片索引返回图片名
function getImageName(name,index){
//img/angry/angry_00.jpg
return "img/"+name+"/"+name+"_"+getIndex(index)+".jpg" ;
}
//实现02功能
function getIndex(index){
//若小于10,拼接一个0
if(index<10){
return "0"+index;
}else{
return index;
}
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
body,html{
width:100%;
height:100%;
}
#cat{
position: absolute;
width: 100%;
height: 100%;
}
img{
position: absolute;
width:50px;
}
#cymbal{
left: 5%;
bottom: 40%;
}
#eat{
left: 5%;
bottom:20%
}
#drink{
left: 5%;
bottom: 30%;
}
#fart{right: 5%;bottom: 40%;}
#pie{right: 5%;bottom: 30%;}
#scratch{right: 5%;bottom: 20%;}
</style>
</head>
<body>
<img id="cat" src="img/angry/angry_00.jpg"/>
<!--加载按钮-->
<img id="cymbal" src="img/cymbal/cymbal.png">
<img id="eat" src="img/eat/eat.png">
<img id="drink" src="img/drink/drink.png">
<img id="pie" src="img/pie/pie.png">
<img id="fart" src="img/fart/fart.png">
<img id="scratch" src="img/scratch/scratch.png">
<script>
var timer;
window.onload=function(){
// 点击相应按钮,播放相应图片。动画名称,图片总数
document.getElementById("cymbal").onclick=function(){
startAnimation("cymbal",12);
}
document.getElementById("eat").onclick=function(){
startAnimation("drink",81);
}
document.getElementById("drink").onclick=function(){
startAnimation("eat",40);
}
document.getElementById("fart").onclick=function(){
startAnimation("fart",28);
}
document.getElementById("pie").onclick=function(){
startAnimation("pie",24);
}
document.getElementById("scratch").onclick=function(){
startAnimation("scratch",56);
}
}
//播放动画的方法,动画名称和图片总数
function startAnimation(name,count){
clearInterval(timer);
var index=0;
var img=document.getElementById("cat");
timer=setInterval(function(){
//判断是否可以继续播放
if(++index<count){
img.src=getImageName(name,index);
}else{
//没有可以播放的图片,清楚定时器
clearInterval(timer);
}
},80);
}
//图片路径
//根据动画名和图片索引返回图片名
function getImageName(name,index){
//img/angry/angry_00.jpg
return "img/"+name+"/"+name+"_"+getIndex(index)+".jpg" ;
}
//实现02功能
function getIndex(index){
//若小于10,拼接一个0
if(index<10){
return "0"+index;
}else{
return index;
}
}
</script>
</body>
</html>
相关文章推荐
- tomcat服务器下使用nginx实现最简单的动静分离--解决css、js不加载的问题
- JS+Canvas实现的俄罗斯方块游戏完整实例
- js+canvas实现简单的五子棋游戏
- HTML5 + js 贪吃蛇游戏设计与实现
- 用JS实现简易贪吃蛇游戏
- JavaScript强化教程 —— JS实现一个基本的打地鼠游戏
- html,css,js实现老虎机游戏以及出现的问题
- 纯原生js实现贪吃蛇游戏
- 用JS实现贪吃蛇游戏
- 100行JS实现HTML5的3D贪吃蛇游戏
- 利用cors,实现js跨域访问Tomcat下资源
- 原生js实现打字动画游戏
- HTML5+JS 《五子飞》游戏实现(一)规则
- 如果一个游戏上面加一个透明层,js能不能实现 点击透明层的任意点 而正常玩游戏
- js实现web网页版台球游戏
- 用js写“算24”游戏的思路分析与实现代码
- JS数字抽奖游戏实现方法
- 简单的JS实现猜数游戏
- HTML5+JS 《五子飞》游戏实现(七)游戏试玩
- canvas+js实现贪吃蛇游戏