Results 1 to 2 of 2

Thread: Hide mouse cursor for a second

  1. #1
    Join Date
    Sep 2016
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Hide mouse cursor for a second

    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


    Code:
    <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>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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):

    Code:
    <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>
    Last edited by jscheuer1; 09-24-2016 at 03:10 PM. Reason: code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    agungbudiono (09-24-2016)

Similar Threads

  1. Power Zoomer - hide cursor
    By portman in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 10-25-2012, 11:23 AM
  2. Hide cursor
    By Grandma Lois in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 09-10-2005, 10:08 PM
  3. Image over mouse cursor ...
    By shachi in forum JavaScript
    Replies: 0
    Last Post: 08-09-2005, 04:18 PM
  4. Mouse cursor and trailing
    By gjoaquin in forum JavaScript
    Replies: 3
    Last Post: 07-28-2005, 09:38 PM
  5. mouse cursor
    By iknowu99 in forum JavaScript
    Replies: 5
    Last Post: 07-26-2005, 08:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •