Hey Friends,
Here i have created a fun project using html css and javascript.
You can find the tutorial video link below
Github Source Code
https://github.com/Rizwan17/youtube-videos-project/tree/master/emojiindex.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>Emoji</title>
<link rel="stylesheet" href="./style.css">
<script src="./index.js" defer></script>
</head>
<body>
<section class="face">
<div class="eye">
<div class="pupil"></div>
</div>
<div class="eye">
<div class="pupil"></div>
</div>
<div class="lips"></div>
</section>
</body>
</html>
style.css
*{
margin: 0;
padding: 0;
}
body{
background-color: #333;
}
.face{
width: 500px;
height: 500px;
background: orange;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
margin-left: -250px;
margin-top: -250px;
}
.eye{
width: 200px;
height: 200px;
position: absolute;
background: #fff;
border-radius: 50%;
top: 100px;
overflow: hidden;
}
.eye:nth-child(1){
left: 40px;
}
.eye:nth-child(2){
right: 40px;
}
.pupil{
width: 50px;
height: 50px;
background: #000;
border-radius: 50%;
position: absolute;
left: 50%;
top: 50%;
margin-left: -25px;
margin-top: -25px;
}
.lips{
width: 400px;
height: 400px;
background: transparent;
border-radius: 50%;
position: absolute;
bottom: 80px;
left: 50%;
margin-left: -200px;
border: 5px solid #000;
border-color: transparent transparent #000 transparent;
}
index.js
const handleMouseMove = (e) => {
const { clientX, clientY } = e;
console.log({ clientX, clientY });
const { innerWidth, innerHeight } = window;
const fractionX = clientX / innerWidth;
const fractionY = clientY / innerHeight;
console.log({ fractionX, fractionY });
const pupilX = -70 + fractionX * 140;
const pupilY = -70 + fractionY * 140;
console.log({ pupilX, pupilY });
document.querySelectorAll('.pupil')
.forEach(el => {
el.style.transform = `translate(${pupilX}px, ${pupilY}px)`;
})
}
window.addEventListener('mousemove', handleMouseMove);