Do you want this to fade in on page load or at a certain time or after a specific event?
You might want to try something along the lines of:
Code:
<!DOCTYPE html>
<style type="text/css">
#test{ background-image: url(someimage.png); opacity: 0;}
</style>
<div id="test" />
<script type="text/javascript">
window.addEventListener("load", fade, false);
// Calls on load.
function fade()
{
var opacity = document.getElementById("test").style.opacity;
var fade_in = 0;
// Calls an interval every 100 ms.
fade_in = setInterval(function()
{
if(opacity == "" || opacity == "undefined" || opacity == "null")
{
// You may have issues incrementing opacity this way. Not sure.
document.getElementById("test").style.opacity += 0.1;
if(opacity >= 1.0)
{
clearInterval(fade_in);
return false;
}
}
}, 100);
}
</script>
This is not tested code so you might have bugs, but this is how I would go about writing a fade function. If you have some code you can post that you'd prefer to use then feel free to show it. This gives me an idea for a tutorial actually, thanks for the idea!
Bookmarks