Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-22-2012, 07:12 PM   PM User | #1
DanCorb
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
DanCorb is an unknown quantity at this point
Displaying a gif before a page loads for a fixed amount of seconds

Hi all,

I want to implement this on my website: http://article.onlinewebtool.com/sho...cript-and-css/

However, I don't want the loading gif to just display until the page loads. I want the gif to display for a fixed amount of time.

So, for example, if I want that loading gif to display for 15 seconds before the page is displayed, how do I do that?

Thanks.
DanCorb is offline   Reply With Quote
Old 09-22-2012, 07:59 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by DanCorb View Post
Hi all,

I want to implement this on my website: http://article.onlinewebtool.com/sho...cript-and-css/

However, I don't want the loading gif to just display until the page loads. I want the gif to display for a fixed amount of time.

So, for example, if I want that loading gif to display for 15 seconds before the page is displayed, how do I do that?

Thanks.
Use setTimeout() to hide the image after 15 seconds.
And then reveal the rest of the page.
Code:
<body onload = "setTimeout(hideshow,15000)"> 

<div id = "loading" style="display:block">
<img src = "loadingimage.gif">
</div>
<div id = "content" style="display:none">
The rest of your page here
</div>

<script type = "text/javascript">
function hideshow() {
document.getElementById("loading").style.display="none";
document.getElementById("content").style.display="block";
}
</script>
Paralympic swimming is going through the roof, quite literally. - Commentator Channel 4
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:46 AM.


Advertisement
Log in to turn off these ads.