The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!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>Happy Valentine's Day</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div>
<h1>Happy Valentine's Day</h1>
<h3>"To love and be loved is to feel the sun from both sides."</h3>
<p>Click on screen to see hearts coming.</p>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
* {
margin: 0;
padding: 0;
}
body {
background-color: #D5ADC8;
background-image: linear-gradient(45deg, #D5ADC8, #FF8489);
height: 100vh;
width: 100%;
text-align: center;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}
h1 {
color: #8D0000;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
z-index: -1;
}
h3 {
color: #660000;
position: absolute;
top: 10%;
transform: translateY(-10%);
left: 0;
right: 0;
z-index: -1;
}
p {
position: absolute;
bottom: 5%;
left: 0;
right: 0;
color: #333;
}
.heart {
z-index: 999;
animation: heartFade 6s linear;
position: absolute;
}
.heart:before, .heart:after {
content: "";
background-color: #FF160C;
position: absolute;
height: 30px;
width: 45px;
border-radius: 15px 0px 0px 15px;
}
.heart:before {
transform: rotate(45deg);
}
.heart:after {
left: 10.5px;
transform: rotate(135deg);
}
@keyframes heartFade {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
Below is the javascript code for this video.
index.js
var board = document.createElement("div");
document.body.insertBefore(board, document.getElementById("board"));
const duration = 3000;
const speed = 0.5;
const cursorXOffset = 0;
const cursorYOffset = -5;
var hearts = [];
function generateHeart(x, y, xBound, xStart, scale) {
var heart = document.createElement("div");
heart.setAttribute('class', 'heart');
board.appendChild(heart);
heart.time = duration;
heart.x = x;
heart.y = y;
heart.bound = xBound;
heart.direction = xStart;
heart.style.left = heart.x + "px";
heart.style.top = heart.y + "px";
heart.scale = scale;
heart.style.transform = "scale(" + scale + "," + scale + ")";
if (hearts == null)
hearts = [];
hearts.push(heart);
return heart;
}
var down = false;
var event = null;
document.onmousedown = function (e) {
down = true;
event = e;
}
document.onmouseup = function (e) {
down = false;
}
document.onmousemove = function (e) {
down = true;
event = e;
}
document.ontouchstart = function (e) {
down = true;
event = e.touches[0];
}
document.ontouchend = function (e) {
down = false;
}
document.ontouchmove = function (e) {
event = e.touches[0];
}
var before = Date.now();
var id = setInterval(frame, 5);
var gr = setInterval(check, 100);
function frame() {
var current = Date.now();
var deltaTime = current - before;
before = current;
for (i in hearts) {
var heart = hearts[i];
heart.time -= deltaTime;
if (heart.time > 0) {
heart.y -= speed;
heart.style.top = heart.y + "px";
heart.style.left = heart.x + heart.direction * heart.bound * Math.sin(heart.y * heart.scale / 30) / heart.y * 200 + "px";
}
else {
heart.parentNode.removeChild(heart);
hearts.splice(i, 1);
}
}
}
function check() {
if (down) {
var start = 1 - Math.round(Math.random()) * 2;
var scale = Math.random() * Math.random() * 0.8 + 0.2;
var bound = 30 + Math.random() * 20;
generateHeart(event.pageX - board.offsetLeft + cursorXOffset, event.pageY - board.offsetTop + cursorYOffset, bound, start, scale);
}
}
Thanks for visiting