Happy Valentine's Day Animation Using HTML CSS And Js
Hey there, You are most welcome to this article. I hope you will enjoy this article. If you like this article then please share this article with your friends and colleagues. If you have any questions or suggestions regarding this article then please comment down below.
๐Table Of Content
- Project Folder Structure of Happy Valentine's Day Animation
- Happy Valentine's Day Animation HTML CODE
- Happy Valentine's Day Animation CSS CODE
- Happy Valentine's Day Animation Javascript CODE
- Video Preview Of Happy Valentine's Day Animation
Project Folder Structure:
- Create a file called index.html to serve as the main file.
- Create a file called style.css for the CSS code.
- Create a file called script.js for the JavaScript code.
Happy Valentine's Day Animation HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Happy Valentine's Day Animation Using HTML CSS And Js </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h2 class="question">Will you go out with me?</h2>
<img class="gif" alt="gif" src="first.gif">
<div class="btn-group">
<button class="yes-btn">Yes</button>
<button class="no-btn">No</button>
</div>
</div>
<script src="main.js"></script>
</body>
</html>
Happy Valentine's Day Animation CSS CODE
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
font-family: Verdana, Geneva, Tahoma, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #fff;
}
.gif{
height: 100%;
width: 100%;
}
h2{
text-align: center;
font-size: 1.5em;
color: #e94d58;
margin: 15px 0;
}
.btn-group{
width: 100%;
height: 50px;
display: flex;
justify-content: center;
margin-top: 30px;
}
button{
position: absolute;
width: 150px;
height: inherit;
color: #fff;
font-size: 1.2em;
border-radius: 30px;
outline: none;
cursor: pointer;
box-shadow: 0 2px 4px gray;
border: 2px solid #e94d58;
}
.yes-btn{
margin-left: -200px;
background: #e94d58;
}
.no-btn{
margin-right: -200px;
background-color: white;
color: #e94d58;
}
Happy Valentine's Day Animation Javascript CODE
const container = document.querySelector(".container");
const question = document.querySelector(".question");
const gif = document.querySelector(".gif");
const yesBtn = document.querySelector(".yes-btn");
const noBtn = document.querySelector(".no-btn");
const btnGrp = document.querySelector(".btn-group");
yesBtn.addEventListener("click", () => {
question.innerHTML = "Yayy, see you tomorrow!";
gif.src ="second.gif";
yesBtn.innerHTML= "Okay"
yesBtn.addEventListener("click", () =>{
question.innerHTML = "Byeee";
gif.src ="third.gif";
noBtn.style.display= "none"
yesBtn.style.display= "none"
});
});
noBtn.addEventListener("mouseover", () => {
const noBtnRect = noBtn.getBoundingClientRect();
const x = window.innerWidth - noBtnRect.width;
const y = window.innerHeight - noBtnRect.height;
const randomX = Math.floor(Math.random() * x);
const randomY = Math.floor(Math.random() * y);
noBtn.style.left = randomX + "px";
noBtn.style.top = randomY + "px";
});
Video Preview Of Happy Valentine's Day Animation
How to run this Html Css and Js Project in Our Browser?
first, you need a code editor either you can use VS code studio or notepad and then copy the html,css, and javascript code, create separate or different files for coding then combine them, after creating file just click .html file or run from VS Code studio and you can project preview.
Which Code Editor do you use to create those projects?
I am using VS Code Studio.
is this project responsive or not?
Yes! this project is a responsive project.
If you enjoyed reading this post and have found it useful for you, then please give share it with your friends, and follow me to get updates on my upcoming posts. You can connect with me on Instagram
if you have any confusion Comment below or you can contact us by filling out our Contact Us form from the home section. ๐ค๐

No comments:
Post a Comment