100-project-100-days-website/100_projects/84-eyes-follow-mouse/main.js
2023-05-16 09:31:53 +03:00
Ask

14 lines
583 B
JavaScript

{7c238aed164b692b936d3f559b171a61e84f0768 true 583 main.js 0xc001fa0e00}

var balls = document.getElementsByClassName("ball");
document.onmousemove = function(){
var x = event.clientX * 100 / window.innerWidth + "%";
var y = event.clientY * 100 / window.innerHeight + "%";
//event.clientX => get the horizontal coordinate of the mouse
//event.clientY => get the Vertical coordinate of the mouse
//window.innerWidth => get the browser width
//window.innerHeight => get the browser height
for(var i=0;i<2;i++){
balls[i].style.left = x;
balls[i].style.top = y;
balls[i].style.transform = "translate(-"+x+",-"+y+")";
}
}