Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Last active December 20, 2021 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidGodzilla/33ad45808e995a7e3ec714fd83db3017 to your computer and use it in GitHub Desktop.
Save kidGodzilla/33ad45808e995a7e3ec714fd83db3017 to your computer and use it in GitHub Desktop.
Hide Idle Cursor until mousemove after 5s delay
/**
* jQuery
*/
$(function () {
$(document).mousemove(function () {
$('html, body').css({ cursor: 'default' });
clearTimeout(window.__ttimer);
window.__ttimer = setTimeout(function () {
$('html, body').css({ cursor: 'none' });
}, 5000);
});
});
/**
* Vanilla
*/
document.body.addEventListener('mousemove', e => {
document.body.style.cursor = 'default';
clearTimeout(window.__ttimer);
window.__ttimer = setTimeout(function () {
document.body.style.cursor = 'none';
}, 5000);
});
/**
* If you enjoy code golf, improve this:
*/
// 148
db=document.body;dbs=db.style;db.addEventListener('mousemove',(e,t)=>{dbs.cursor='default';clearTimeout(t);t=setTimeout(e=>dbs.cursor='none',5e3)});
// 129
db=document.body;dbs=db.style;db.onmousemove=(e,t)=>{dbs.cursor='default';clearTimeout(t);t=setTimeout(f=>dbs.cursor='none',5e3)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment