Jump to content

Display an image 8 seconds after page load


npsari

Recommended Posts

Hello :happy-04:

I have this code which shows an image for 5 seconds then it disapears

However, instead of clicking a button, I want this to happen automatically 8 seconds after page load

 

<input type = "button" value = "Show image for 5 seconds" onclick = "show()"><br><br>

<div id = "myDiv" style="display:none"><img id = "myImage" src = "/images/logo.png"></div><br>

<script type = "text/javascript">

function show() {
document.getElementById("myDiv").style.display="block";
setTimeout("hide()", 5000); // 5 seconds
}

function hide() {
document.getElementById("myDiv").style.display="none";
}

</script>

 

If there are any experts out there, please provide code

Thank you both

I've done it like this, but it is not working:

 

<script type="text/javascript">
<!--

function delayer(){



function show() {
document.getElementById("myDiv").style.display="block";
setTimeout("hide()", 5000); // 5 seconds
}

function hide() {
document.getElementById("myDiv").style.display="none";
}



}

<body onload="setTimeout('delayer()', 8000)">

//-->
</script>

okay, i've done the show

but the hide i cant

please help

 

 

<script type="text/javascript">
<!-- 

function delayer(){

   document.getElementById("myDiv").style.display="block";

} 


//-->
</script>


<div id = "myDiv" style="display:none"><img id = "myImage" src = "/images/logo.png"></div><br>

<body onload="setTimeout('delayer()', 8000)">

Okay, I've done it

Thank you much guys

 

<script type="text/javascript">
<!-- 

function delayer(){

   document.getElementById("myDiv").style.display="block";
   setTimeout("hide()", 5000);  // 5 seconds
} 


function hide() {
   document.getElementById("myDiv").style.display="none";
}

//-->
</script>


<div id = "myDiv" style="display:none"><img id = "myImage" src = "/images/logo.png"></div><br>

<body onload="setTimeout('delayer()', 8000)">

I wanted to let ya figure it out on your own first, but here. (:

Demo: http://xaotique.no-ip.org/tmp/41/

 

// When page loads ...
window.addEventListener("load", function()
{
   // Run in 8 seconds
   setTimeout(function()
   {
       // Put div into variable and show it
       var div = window.document.querySelector("#myDiv");
       div.style.display = "block";

       // Run in 5 seconds
       setTimeout(function()
       {
           // Hide div
           div.style.display = "none";
       }, 5000);
   }, 8000);
}, false);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.