Created
June 14, 2018 14:33
-
-
Save jeangontijo/b0a62d5df838430efe29268247f57014 to your computer and use it in GitHub Desktop.
Proximity Sensor
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
document.addEventListener("mousemove", function (event) { | |
const x = event.pageX | |
const y = event.pageY | |
document.querySelectorAll("div").forEach(div => { | |
const dx = (div.offsetLeft + 50) - x | |
const dy = (div.offsetTop + 50) - y | |
const dist = Math.sqrt(dx * dx + dy * dy) | |
const score = Math.exp(dist * -0.003) | |
// use examples | |
div.style.transform = "scale(" + score + ")" | |
div.style.fontWeight = 100 + (100 * Math.floor(8 * score)) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment