Last active
December 3, 2018 11:59
-
-
Save glzjin/1a4288d3d8364b5f9e95d059a3284e7b to your computer and use it in GitHub Desktop.
Mouse Follow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Mouse Follow</title> | |
<style> | |
#p { | |
text-align: center; | |
-webkit-appearance: none; | |
-moz-appearance: none; | |
appearance: none; | |
} | |
</style> | |
</head> | |
<body> | |
<progress id="p" value=55 max="100" style="height: 200px; width: 1500px"></progress> | |
</body> | |
</html> | |
<script type="text/javascript"> | |
function getViewport() { | |
if (document.compatMode == "BackCompat") { | |
return { | |
width: document.body.clientWidth, | |
height: document.body.clientHeight | |
} | |
} else { | |
return { | |
width: document.documentElement.clientWidth, | |
height: document.documentElement.clientHeight | |
} | |
} | |
} | |
window.addEventListener("mousemove", (e) => { | |
let screen = getViewport() | |
document.getElementById("p").style.width = screen.width | |
let percent = e.clientX / screen.width * 100 | |
document.getElementById("p").value = percent | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment