Native js realizes automatic drop down and at the top of web page to shrink advertising effect
- 2021-07-13 03:46:54
- OfStack
Key points of knowledge
1. Implementation principle:
By recursively changing the height value of div, the effect of slow pull-down is achieved.
2.1 There are three steps. I wrote three functions
First show () function (drop down): Initial height h < 300, h+5, whereas return exits and stops, call setTimeout method to execute once in 30 milliseconds +5
The second hide () function (retracted): only the height of the judgment of different heights h-5 otherwise return exit stop, call setTimeout method 30 milliseconds to execute once-5
The third dd () function (popped up again): Note here that the second div popped up is a new div with its height set to 0. The implementation principle is the same as the first function 1.
And 1 must be executed after the second function (retraction) is executed
Complete code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demo</title>
<style>
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;}
h1,h2,h3,h4,h5,h6{font-size:100%;}
address,cite,dfn,em,var{font-style:normal;}
code,kbd,pre,samp{font-family:courier new,courier,monospace;}
ul,ol{list-style:none;}
a{text-decoration:none;}
a:hover{text-decoration:none;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
legend{color:#000;}
fieldset,img{border:0;}
button,input,select,textarea{font-size:100%;}
table{border-collapse:collapse;border-spacing:0;}
.clear{clear: both;float: none;height: 0;overflow: hidden;}
#container{width: 600px; margin: 0 auto;}
p{ line-height: 28px; }
.hidden{background: #E6E6E6; text-align: center; height: auto; overflow: hidden;}
.show{ background: #808080;text-align: center; height: 0; overflow: hidden; }
</style>
</head>
<body>
<div id="container">
<div class="hidden" id="hid"><p> Advertisement map </p></div>
<div class="show" id="sho"><p> Ha ha ha ha successful modification </p></div>
</div>
<script type="text/javascript">
window.onload=function aa(){
show();
setTimeout("hide()",3000);
}
var h=0;
var hid=document.getElementById("hid");
var sho=document.getElementById("sho");
function show(){
if(h<300){
h+=5;
hid.style.height=h+"px";
}else{
return;
}
setTimeout("show()",30);
}
function hide(){
if(h>0){
h-=5;
hid.style.height=h+"px";
}else{
dd();
return;
}
setTimeout("hide()", 30);
}
var a=0;
function dd(){
if(a<60){
a+=1;
sho.style.height=a+"px";
}else{
return;
}
setTimeout("dd()",30);
}
</script>
</body>
</html>