Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active March 4, 2017 12:49
Show Gist options
  • Save vincentorback/2ca661ece4ccd5192214f7ff1857b0fd to your computer and use it in GitHub Desktop.
Save vincentorback/2ca661ece4ccd5192214f7ff1857b0fd to your computer and use it in GitHub Desktop.
hideIdleCursor.js
const targetEl = document.querySelector('.js-target')
const hideMouse = false
const idleTime = 3000
let idleMouseTimer
targetEl.addEventListener('mousemove', (e) => {
if (!hideMouse) {
targetEl.style.cursor = ''
clearTimeout(idleMouseTimer)
idleMouseTimer = setTimeout(() => {
targetEl.style.cursor = 'none'
hideMouse = true
setTimeout(() => {
hideMouse = false
}, 200)
}, idleTime)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment