Skip to content

Instantly share code, notes, and snippets.

@josephwegner
Created September 20, 2011 12:31
Show Gist options
  • Save josephwegner/1228975 to your computer and use it in GitHub Desktop.
Save josephwegner/1228975 to your computer and use it in GitHub Desktop.
Hide your cursor on a web page when it is idle. Great if you're using a web page for some sort of TV Display and don't want the cursor messing things up.
//Requires jQuery - http://code.jquery.com/jquery-1.6.4.min.js
$(document).ready(function() {
var idleMouseTimer;
var forceMouseHide = false;
$("body").css('cursor', 'none');
$("#wrapper").mousemove(function(ev) {
if(!forceMouseHide) {
$("body").css('cursor', '');
clearTimeout(idleMouseTimer);
idleMouseTimer = setTimeout(function() {
$("body").css('cursor', 'none');
forceMouseHide = true;
setTimeout(function() {
forceMouseHide = false;
}, 200);
}, 1000);
}
});
});
@JohnTC
Copy link

JohnTC commented Mar 6, 2021

Okay, but how can I stop the mouse hiding?

@josephwegner
Copy link
Author

should be able to just move your mouse. It automatically unhides with movement.

@JohnTC
Copy link

JohnTC commented Mar 6, 2021

It should only work on fullscreen ... on normal screen the function should stop.
I tried it with $('#wrapper').off("mousemove"); … but that does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment