Home  >  Article  >  Web Front-end  >  Web advertising special effects code sharing

Web advertising special effects code sharing

巴扎黑
巴扎黑Original
2017-08-21 09:59:371721browse

The following editor will bring you a simple example of web advertising special effects. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

In order to practice javascript, I made a simple demo. What is achieved is that the advertisement is slowly pulled out from the top to the maximum, then stays for 2 seconds, and then shrinks to a smaller size and can be closed. advertising special effects. The picture can be replaced with any other picture.

The code is as follows


<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
 <style>
  #ad{
   width:962px;
   display:none;
   margin:0 auto;
   overflow:hidden;
   position:relative;
  }
  #main{
   margin:0 auto;
   width:960px;
   height:1700px;
  }
  #close{
   width:20px;
   height:20px;
   position:absolute;
   top:0;
   right:0;
   font-size:16px;
   line-height:20px;
   text-align:center;
   display:none;
   background:yellowgreen;
  }
 </style>

</head>
<body>
<p id="ad">
 <img src="ad.png" id="imgAd" width="962" height="386">
 <img src="cur.png" id="curAd" width="1199" height="68">
 <span id="close">x</span>
</p>
<p id="main"><img src="数字商品-10-23.jpg"></p>
<script>
 var oImgAd=document.getElementById(&#39;imgAd&#39;);
 var oad=document.getElementById(&#39;ad&#39;);
 var ocur=document.getElementById(&#39;curAd&#39;);
 var closeBtn=document.getElementById(&#39;close&#39;);
 var h=0;
 var maxH=oImgAd.height;
 var minH=ocur.height;
 function down()
 {
  if(h<maxH)
  {
   h+=5;
   oad.style.height=h+"px";
   oad.style.display="block";
   setTimeout(down,5);
  }
  else{
   setTimeout(up,2000);
  }
 }
 function up(){
  if(h>minH){
   h-=5;
   oad.style.height=h+"px";
   setTimeout(up,5);
  }
  else{
   oImgAd.style.display=&#39;none&#39;;
   closeBtn.style.display=&#39;block&#39;;
  }
 }
 closeBtn.onclick=function(){
  oad.style.display=&#39;none&#39;;
 }
 setTimeout(down,1000);
</script>
</body>
</html>

The above is the detailed content of Web advertising special effects code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn