Click here to Skip to main content
15,880,427 members
Articles / Web Development / HTML
Tip/Trick

How to Replace a Web Page's Default Hourglass with a Fancy One

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
22 Sep 2016CPOL 13.9K   2   2
A simple way to add a fancy-pants custom "hourglass" to your page with a (very) little HTML and JavaScript

The Gilded Age

I was using the built-in "wait cursor" to begin "hourglassing" when an operation began, like so:

JavaScript
document.body.style.cursor = 'wait';

...and then changing it back to the default when the operation completed, like so:

JavaScript
document.body.style.cursor = 'pointer';

For some reason, that blue spinny donutesque thingy gave my manager the fantods, though, so I replaced it with a fancy-pants, whiz-bang, gold-leaf, kid-glove, diamond-breastpin "hourglass" this way:

Add a line of HTML to reference the "Font Awesome" fonts:

HTML
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" 
rel="stylesheet" type="text/css" 

Then add a "span" HTML element in your code where you want the "hourglass" to (sometimes) display, like so:

HTML
<span id="newhourglass" 
class="fa fa-4x fa-refresh fa-spin boxRefresh hide" runat="server"></span>

Finally, add the JavaScript to unhide the font character/hourglass like so:

JavaScript
$("#newhourglass").removeClass("hide");

...and then hide it again like so:

JavaScript
$("#newhourglass").addClass("hide");

In context, you might have code something like this:

JavaScript
$("body").on("click", "#btnGetData",
    function () {
        //document.body.style.cursor = 'wait';
        $("#newhourglass").removeClass("hide");

        $.ajax({
	        . . .
            success: function (returneddata) {
                $("body").html(returneddata);
                //document.body.style.cursor = 'pointer';
                $("#newhourglass").addClass("hide");
            },
            error: function () {
                console.log('error in ajax call');
                //document.body.style.cursor = 'pointer';
                $("#newhourglass").addClass("hide");
            }
        });
    });

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006: http://www.lulu.com/spotlight/blackbirdcraven

Comments and Discussions

 
Praise+1 for the colorful writing Pin
Kent K26-Sep-16 3:19
professionalKent K26-Sep-16 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.