<!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>Document</title>
<script src="jquery-1.9.0.min.js"></script>
<style>
#game {
width: 800px;
height: 480px;
margin: 40px auto;
background: url('imgs/background.png');
animation: gamemove 1s steps(6) infinite;
position: relative;
overflow: hidden
}
@keyframes gamemove {
0% {
background-position: 0
}
100% {
background-position: 100%
}
}
.em {
position: absolute;
width: 100px;
height: 40px;
background: url('imgs/fire.png');
animation: emmove 1s steps(3) infinite, toLeft 6s linear forwards
}
.enemy-bullet{
position: absolute;
width: 50px;
height: 5px;
background: white;
animation: toLeft 2s linear forwards;
}
@keyframes emmove {
0% {
background-position: 0
}
100% {
background-position: 100%
}
}
@keyframes toLeft {
to {
transform: translateX(-1200px)
}
}
#planet1 {
background: url(imgs/planet-4.png);
background-size: 100%;
width: 100px;
height: 100px;
position: absolute;
top: 40px;
animation: planet1 10s steps(210) infinite
}
@keyframes planet1 {
0% {
right: -100px;
}
100% {
right: 900px;
}
}
</style>
</head>
<body>
<div id='game'>
<div class="enemy-bullet"></div>
</div>
</body>
</html>
<script>
game = $('#game');
planet1 = $("<div id='planet1'></div>");
em = $("<div id='em'></div>");
em.appendTo(game).css({ 'right': '0' })
game.append(planet1)
function createEle(name, attr, css) {
let ele = $(`<div class="${name}"></div>`).appendTo(game);
ele.attr(attr).css(css).css('animation-play-state', 'running').on('webkitAnimationEnd', function () {
$(this).remove();
})
}
function create() {
createEle('em', {
fuel: 0,
life: 1,
score: 5
}, {
left: '100%',
top: 200
})
}
create();
enemy_bullet()
function enemy_bullet() {
let enemys = $(".em");
enemys.each(function () {
let left = $(this).position().left;
let top = $(this).position().top;
createEle('enemy-bullet',{
fuel :0,
life:0,
score:0
} ,{
left: left - 50,
top: top + 20
});
})
}
timerCreate();
function timerCreate(){
setInterval(function(){
create();
enemy_bullet();
}, 2000)
}
</script>
网友评论