Skip to content

Instantly share code, notes, and snippets.

@jeangontijo
Created June 14, 2018 14:33
Show Gist options
  • Save jeangontijo/b0a62d5df838430efe29268247f57014 to your computer and use it in GitHub Desktop.
Save jeangontijo/b0a62d5df838430efe29268247f57014 to your computer and use it in GitHub Desktop.
Proximity Sensor
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