How to create colorful heart on mouse move using JavaScript

Hello friends, today we will be going to create colorful heart on mousemove using HTML CSS & JavaScript. I have posted many videos and articles before related to the JavaScript project, now this the something new that we are going to build.

Demo Tutorial of How to create colorful heart on mousemove using HTML CSS & JavaScript


As you have seen on the given demo tutorial of  How to create colorful heart on mousemove using HTML CSS & JavaScript, 

If you are feeling bored watching the given demo tutorial of How to create colorful heart on mousemove using HTML CSS & JavaScript then you can copy or download the given codes below:


How to create colorful heart on mousemove using HTML CSS & JavaScript | Free Source Code

To create this program (Colorful Heart). First, you need to create two Files one HTML File and another one is CSS File. After creating these files just paste the following codes in your file.

In the first place, make a HTML document with the name of index.html and glue the given codes in your HTML record. Keep in mind, you've to make a document with .html extension.
<!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'>
	<link rel='stylesheet' href='style.css'>
	<title>Document</title>
	<!-- S-Tech04 | www.youtube.com/STech04 -->
</head>
<body>
	<script>
		document.addEventListener('mousemove',(e)=>{
			let body = document.querySelector('body');
			let span = document.createElement('span');
			let x = e.offsetX;
			let y = e.offsetY;
			span.style.top = y + "px";
			span.style.left = x + "px";
			let size = Math.random() * 100;
			span.style.height = 20 + size + "px";
			span.style.width = 20 + size + "px";
			body.appendChild(span);

			setTimeout(()=>{
				span.remove();
			},2000)
		})
	</script>
</body>
</html>
Second, make a CSS record with the name of style.css and glue the given codes in your CSS document. Keep in mind, you've to make a record with .css extension.
*{
	margin: 0;
	padding: 0;
}
body
{
	width: 100%;
	overflow: hidden;
	height: 100vh;
	background: #333;
}
span
{
	position: absolute;
	background: url(./heart.png);
	background-size: cover;
	pointer-events: none;
	transform: translate(-50%,-50%);
	animation: animate 2s linear infinite;
}
@keyframes animate
{
	0%{
		transform: translate(-50%,-50%);
		opacity: 1;
		filter: hue-rotate(0deg);
	}
	100%{
		transform: translate(-50%,-1000%);
		opacity: 0;
		filter: hue-rotate(720deg);
	}
}
That's all, now you've successfully created a program to create colorful heart on mousemove using HTML CSS & JavaScript. If your code doesn't work or you've faced any error/problem, please download the source code files from the given download button. It's free and a .zip file will be downloaded then you've to extract it.
Click on the following download button to download all source code files.


Download Now
Please Wait...
Direct Link click here.

How can I help you

Post a Comment

How can I help you

Post a Comment (0)

Previous Post Next Post