I have just started learning CSS and JS, and despite reviewing my code multiple times, consulting w3schools, and searching for similar issues, I am still unable to pinpoint where the error lies.
<! DOC TYPE HTML>
<html>
<head>
<h1> fruit dodge</h1>
<link rel="stylesheet" href="FDCSS.css">
</head>
<body onkeypress="jump()">
<div id="game">
<div id="player"></div>
In an attempt to resolve the issue, I moved the event to the body element from the html tag, but it did not solve the problem as intended.
CSS:
.animate
{
animation: jump 500ms;
}
keyframes jump
{
0%{top: 400px;}
30%{top: 350px;}
70%{top: 350px;}
100%{top: 400px;}
}
I can confirm that the animation itself is functional as I tested it independently before incorporating it into a class.
var player = getElementById("player");
var fruit = getElementById("fruit");
function jump()
{
player.classList.add("animate");
setTimeout(function()
{
player.classList.remove("animate");
},500);
}
The purpose of the jump function is to apply the animate class to the player character momentarily and then remove it after the animation duration (500ms).