PDA

View Full Version : Hide mouse cursor for a second



agungbudiono
09-24-2016, 02:53 AM
Please help me to improve this script

I want to hide mouse cursor for a second, even in mouse move (not only in idle)
I want to use this for my blog with short time visitors pageview like wallpaper blog



<script type="text/javascript">
document.body.style.cursor = 'none';

setTimeout(function (){
document.body.style.cursor = 'unset';
}, 10000); // How long do you want the delay to be (in milliseconds)?

</script>

jscheuer1
09-24-2016, 02:35 PM
Seems to work just like that here - though only on the body element. If you want to do that for every element, there are various ways. I'd prefer using jQuery, let me know if that's available. But without that, this should work (place just before the closing </body> tag near the end of the page):


<script type="text/javascript">
(function(){
var cn = document.body.className, nc = "nocursor", re = /\bnocursor\b/;
while (re.test(cn)){
nc += new Date().getTime();
re = new RegExp('\\b' + nc + '\\b');
}
document.write('<style type="text/css">' +
'body.' + nc + ', body.' + nc + ' * {' +
'cursor: none !important;' +
'}' +
'</style>');
document.body.className = cn? cn + ' ' + nc : nc;

setTimeout(function (){
cn = document.body.className.replace(re, '');
if(cn){
document.body.className = cn;
} else {
document.body.removeAttribute('className');
document.body.removeAttribute('class');
}
}, 10000); // How long do you want the delay to be (in milliseconds)?

})();
</script>