Open
Description
<title>Fly Animation</title>
<style>
#fly {
width: 50px;
height: 50px;
background-color: #3498db;
position: absolute;
}
</style>
<script>
// Get the fly element
const fly = document.getElementById('fly');
// Set initial position of the fly
let positionX = 0;
let positionY = 0;
// Function to move the fly
function moveFly() {
// Update position
positionX += 5;
positionY += 3;
// Set new position
fly.style.left = positionX + 'px';
fly.style.top = positionY + 'px';
// Repeat the animation
requestAnimationFrame(moveFly);
}
// Start the animation
moveFly();
</script>
Metadata
Metadata
Assignees
Labels
No labels