Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Fade in a div with javascript
Old 06-05-2008, 06:25 PM Fade in a div with javascript
Skilled Talker

Posts: 81
Trades: 0
Hi

I'd like to fade in a div using javascript, some seconds after rest of page has loaded.

This code is a simple fade-in:


HTML Code:
<style>logo{filter:alpha(opacity=0);opacity:0}</style>
<script>
function Logo(){var fade=0,logo=document.getElementById("logo").style,ms=(logo.opacity==0)?0:1,pace=setInterval(Fade,20);function Fade(){if(fade<100){fade+=1;if(ms)logo.filter="alpha(opacity="+fade+")";else logo.opacity=(fade/100)}else clearInterval(pace)}};
window.onload=Logo;
</script>
<body><div id="logo">CONTENT</div></body>
This works in IE (if you specify width of div) and FF. However, it did for somereason give an alert in IE7.

Is there any way I can apply timeout to it so the div only fades in after,say, 10 seconds? I have tried,but without success. I can slow the fade-in effects, but that's not what I would like to happen. What i am hoping for is, say, 10 seconds of nothing, then a fade-in over 1 second.

I don't want to go to the extent of the rather long scripts in Scriptaculous. I did find another nice-looking script at
http://www.brandspankingnew.net/archive/2006/09/javascript_css_crossfader.html

but again, though I can change the speed of fade-in, I can't achieve a timeout to make it start late.

Any ideas please?

Many thanks

Tony



__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
 
Register now for full access!
Old 06-05-2008, 08:11 PM Re: Fade in a div with javascript
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What you're looking for is the setTimeout() function.
Here is a quick tutorial about it: http://www.w3schools.com/js/js_timing.asp
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-05-2008, 10:21 PM Re: Fade in a div with javascript
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Drop the onload line and change your body tag to this:
Code:
<body onload="window.setTimeout('Logo()',10000);">
__________________
~nyef

Please login or register to view this content. Registration is FREE

Last edited by nyef; 06-05-2008 at 10:22 PM..
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-06-2008, 07:33 AM Re: Fade in a div with javascript
Skilled Talker

Posts: 81
Trades: 0
Thanks folks, that's great and got it working now.

Best wishes

tony
__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
Reply     « Reply to Fade in a div with javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15679 seconds with 12 queries