-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (25 loc) · 865 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const mario = document.querySelector('.mario');
const pipe = document.querySelector('.pipe');
const jump=() => {
mario.classList.add('jump');
setTimeout(() => {
mario.classList.remove('jump');
}, 500);
}
const loop= setInterval(()=> {
console.assertlog('loop')
const pipepostion = pipe.offsetLeft;
const mariopostion= window.getComputedStyle(mario).bottom.replace('px',' ');
console.log(mariopostion);
if (pipepostion <= 120 && pipepostion >0 && mariopostion< 80){
pipe.style.animation="none";
pipe.style.left=`${pipepostion}px`;
mario.style.animation="none";
mario.style.left=`${mariopostion}px`;
mario.src='dead.jpeg';
mario.style.width= '75px'
mario.style.marginleft = '50px'
clearInterval('loop');
}
}, 10);
document.addEventListener('keydown', jump)