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

Link to comment
Share on other sites

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>

Edited by npsari
Link to comment
Share on other sites

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)">

Link to comment
Share on other sites

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)">

Link to comment
Share on other sites

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);

Edited by Xaotique
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.