Googly Eye
How do I make an googly eye?
What is a googly eye? How do you make a googly eye? This script and codes were developed by Yang Li on 14 January 2023, Saturday.
Googly Eye - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Googly Eye</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id='eyes'> <div class='eye'> <div class='pupil left'></div> </div> <div class='eye'> <div class='pupil right'></div> </div>
</div>
<div id="smile"> <img src="http://vignette3.wikia.nocookie.net/brawloftheobjects/images/5/57/Closed_Mouth_Teeth_Smile.png/revision/latest?cb=20150419054317" alt="">
</div> <script src="js/index.js"></script>
</body>
</html>
Googly Eye - Script Codes CSS Codes
* { background-color: yellow
}
#eyes{ display: flex; justify-content: space-around; align-items: center; margin: 0 auto; width: 600px; height: 300px;
}
#smile img{ display: block; margin: 0 auto; width: 500px; margin-top: -120px;
}
.eye { background-color: white; width: 150px; height: 150px; border-radius: 50%; position: relative;
}
.pupil { position: absolute; background-color: black; width: 80px; height: 80px; border-radius: 50%;
}
Googly Eye - Script Codes JS Codes
// Setting up variables and DOM elements
var cursorX;
var cursorY;
var width = document.documentElement.clientWidth;
var leftX = width/2 - 150;
var rightX = width/2 + 150;
var leftEye = document.getElementsByClassName("left")[0];
var rightEye = document.getElementsByClassName("right")[0];
// Setting up numerical position of pupils
leftEye.style.left = "35px";
leftEye.style.top = "35px";
leftEyeLNum = parseInt(leftEye.style.left)
leftEyeTNum = parseInt(leftEye.style.top)
rightEye.style.left = "35px";
rightEye.style.top = "35px";
rightEyeLNum = parseInt(rightEye.style.left)
rightEyeTNum = parseInt(rightEye.style.top)
// Tracking cursor X and Y by page X and Y
document.onmousemove = function(e){ cursorX = e.pageX; cursorY = e.pageY;
}
function moveEyes(){ // left eye moving left right if(cursorX < leftX && leftEyeLNum > 2){ leftEyeLNum -= 1 leftEye.style.left = leftEyeLNum + "px" } else if (cursorX > leftX && leftEyeLNum < 68){ leftEyeLNum += 1 leftEye.style.left = leftEyeLNum + "px" } // left eye moving up and down if(cursorY < 160 && leftEyeTNum > 10){ leftEyeTNum -= 1 leftEye.style.top = leftEyeTNum + "px" } else if (cursorY > 160 && leftEyeTNum < 60){ leftEyeTNum += 1 leftEye.style.top = leftEyeTNum + "px" } // right eye moving left right if(cursorX < rightX && rightEyeLNum > 2){ rightEyeLNum -= 1 rightEye.style.left = rightEyeLNum + "px" } else if (cursorX > rightX && rightEyeLNum < 68){ rightEyeLNum += 1 rightEye.style.left = rightEyeLNum + "px" } // left eye moving up and down if(cursorY < 160 && rightEyeTNum > 10){ rightEyeTNum -= 1 rightEye.style.top = rightEyeTNum + "px" } else if (cursorY > 160 && rightEyeTNum < 60){ rightEyeTNum += 1 rightEye.style.top = rightEyeTNum + "px" } // Extention: if crossed-eyed, make eyes red if(leftEyeLNum >= 68 && rightEyeLNum <= 3){ leftEye.style.backgroundColor = "brown"; rightEye.style.backgroundColor = "brown"; } else { leftEye.style.backgroundColor = "black"; rightEye.style.backgroundColor = "black"; }
}
// Every 10ms move the eyes slightly depending on cursor location
setInterval(moveEyes, 10);
Developer | Yang Li |
Username | aussieyang |
Uploaded | January 14, 2023 |
Rating | 3 |
Size | 2,468 Kb |
Views | 2,024 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Mac Bar | 2,204 Kb |
Battleships | 2,879 Kb |
Geography Quiz | 2,136 Kb |
Highlight Me Starter | 1,628 Kb |
Battleships Starter | 2,429 Kb |
Recreate Google | 1,853 Kb |
Animated Clock Starter | 1,571 Kb |
Recreate Google Starter | 1,409 Kb |
Simple Hamburger Menu | 2,099 Kb |
Battleships Starter v2 | 2,283 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
STIKHOI | Denmch | 7,122 Kb |
Tree growth tests | Orchard | 3,818 Kb |
Cant get enough icecream in pure css3 | Melawire | 4,322 Kb |
C.Rowe Button | Brownerd | 2,473 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Profile box | Daniesy | 2,766 Kb |
Donald Trump - The New Yorker | Agbales | 2,502 Kb |
HTM5 picture dropzone | Jaysalvat | 2,576 Kb |
Tooltip in table | Roine | 3,713 Kb |
Stylize Stories | Jvhti | 2,465 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!