onload + setTimeout usage, create an ad playing box effect

In general, only

<body>,<img>, <link>, <script>,<frame>, <frameset>, <iframe>, 

Onload attribute label only, there is no other label this event.

A frame shells are summarized below advertising method using onload + setTimeout

<style>

width:200px;

height:200px;

background-color: red;

position: fixed;

top: 0px;

right: 0px;

</style>

<script>

function init(){

var g=document.getElementById("guanggao");

g.style.display="none";

setTimeout(showGuanggao, 3000);

}

function showGuanggao(){

var g=document.getElementById("guanggao");

g.style.display="block";

};

function closeGuanggao(){
var g = document.getElementById("guanggao");
g.style.display ="none";
}

</script>

<body onload="init()">

<div id="guanggao">

<div id="guanggao">
<button onclick="closeGuanggao()">关闭</button>
</div>

</div>

</body>

Guess you like

Origin www.cnblogs.com/lvqiupingboke-2019/p/12073115.html