Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait cursor over entire html page

Is it possible to set the cursor to 'wait' on the entire html page in a simple way? The idea is to show the user that something is going on while an ajax call is being completed. The code below shows a simplified version of what I tried and also demonstrate the problems I run into:

  1. if an element (#id1) has a cursor style set it will ignore the one set on body (obviously)
  2. some elements have a default cursor style (a) and will not show the wait cursor on hover
  3. the body element has a certain height depending on the content and if the page is short, the cursor will not show below the footer

The test:

<html>     <head>         <style type="text/css">             #id1 {                 background-color: #06f;                 cursor: pointer;             }              #id2 {                 background-color: #f60;             }         </style>     </head>     <body>         <div id="id1">cursor: pointer</div>         <div id="id2">no cursor</div>         <a href="#" onclick="document.body.style.cursor = 'wait'; return false">Do something</a>     </body> </html> 

Later edit...
It worked in firefox and IE with:

div#mask { display: none; cursor: wait; z-index: 9999;  position: absolute; top: 0; left: 0; height: 100%;  width: 100%; background-color: #fff; opacity: 0; filter: alpha(opacity = 0);}  <a href="#" onclick="document.getElementById('mask').style.display = 'block'; return false"> Do something</a> 

The problem with (or feature of) this solution is that it will prevent clicks because of the overlapping div (thanks Kibbee)

Later later edit...
A simpler solution from Dorward:

.wait, .wait * { cursor: wait !important; } 

and then

<a href="#" onclick="document.body.className = 'wait'; return false">Do something</a> 

This solution only shows the wait cursor but allows clicks.

like image 571
Aleris Avatar asked Oct 10 '08 20:10

Aleris


People also ask

How do I change my cursor to wait?

We can set the cursor to wait using object. style. cursor = “wait” in javascript.

How do I customize my cursor in HTML?

Answer: Use the CSS cursor property You can define a custom cursor using the CSS cursor property. The cursor property takes the comma-separated list of user-defined cursors value followed by the generic cursor. First of all create cursor image and save it with the extension .

How do I change the cursor when I hover over the button?

You can simply use the CSS cursor property with the value pointer to change the cursor into a hand pointer while hover over any element and not just hyperlink. In the following example when you place the cursor over the list item, it will change into a hand pointer instead of the default text selection cursor.


1 Answers

If you use this slightly modified version of the CSS you posted from Dorward,

html.wait, html.wait * { cursor: wait !important; } 

you can then add some really simple jQuery to work for all ajax calls:

$(document).ready(function () {     $(document).ajaxStart(function () { $("html").addClass("wait"); });     $(document).ajaxStop(function () { $("html").removeClass("wait"); }); }); 

or, for older jQuery versions (before 1.9):

$(document).ready(function () {     $("html").ajaxStart(function () { $(this).addClass("wait"); });     $("html").ajaxStop(function () { $(this).removeClass("wait"); }); }); 
like image 67
Dani Avatar answered Oct 05 '22 22:10

Dani