注:小绵羊是可以拖动的 css文件夹中style.css为主要的样式文件
js文件夹中sheep.js为动画效果功能文件
image中为所用到的图片资源目录
music中为所用到的背景音乐目录
index.html为演示文件
var sheepAnimate = setInterval(function(){
sheep.num = sheep.num sheep.sheepWith;
if(sheep.num == (sheep.sheepWith*8)){
sheep.num = 0;
}
// console.log(sheep.num);
sheep.sheep.style.backgroundPosition = -sheep.num 'px ' sheep.top 'px';
},sheep.frequencyNum);
//实现整个羊走的(位移)动画
var sheepRun = setInterval(function(){
sheep.cot = sheep.sheep.offsetLeft-sheep.speed;
if(sheep.cot<=-sheep.sheepWith){
clearInterval(sheepRun);
clearInterval(sheepAnimate);
sheep.stage.removeChild(sheep.sheep);
}
//console.log(sheep.cot);
sheep.sheep.style.left = sheep.cot 'px';
},sheep.frequencyNum)
评论