Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Eagle Follows Mouse" project using HTML, CSS & JavaScript.
Preview
In the above video, you’ve seen the preview of the "Eagle Follows Mouse" project and I hope now you are able to create this type of project. If not, I have provided all the HTML CSS, and JavaScript code below.
Eagle Follows Mouse [Source Code]
To get the following HTML, CSS & JS code for the Eagle Follows Mouse project. You need to create three files one is an HTML file, the second one is a CSS file and another one is a JS file. After creating these three files then you can copy-paste the given codes on your document.
Remember, you’ve to create a file with a .html extension for HTML code, a .css extension for CSS code, and .js for JavaScript code.
You can also download all source code files from the given download button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eagle Follows Mouse</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<img src="eagle.png" alt="">
</div>
<script src="index.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
}
body {
background: url(sky.jpg);
background-size: cover;
background-repeat: no-repeat;
}
.container {
width: 200px;
position: absolute;
transition: 0.2s ease-out;
}
img {
width: 100%;
}
var containerEl = document.querySelector(".container");
document.addEventListener("mousemove", (event) => {
try {
var x = event.pageX ;
var y = event.pageY;
} catch (error) {
alert(error);
}
containerEl.style.left = x - 120 + "px";
containerEl.style.top = y - 120 + "px";
});