Home > Technology > 首页自动伸缩广告代码大全

首页自动伸缩广告代码大全

February 20th, 2010 Leave a comment Go to comments

第一种:自动展开收缩版。

<script type="text/javascript">

var intervalId = null;  

function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){  

this.stayTime=nStayTime*500 || 3000(展开时间);  

this.maxHeigth=nMaxHth ||**广告页面高度);  

this.minHeigth=nMinHth || 2.5;  

this.state=sState || "down" ;  

var obj = document.getElementById(id);  

if(intervalId != null)window.clearInterval(intervalId);  

function openBox(){  

var h = obj.offsetHeight;  

obj.style.height = ((this.state == "down") ? (h + 9) : (h – 9))+"px";  

if(obj.offsetHeight>this.maxHeigth){  

window.clearInterval(intervalId);  

intervalId=window.setInterval(closeBox,this.stayTime);  

}  

if (obj.offsetHeight<this.minHeigth){  

window.clearInterval(intervalId);  

obj.style.display="none";  

}  

}  

function closeBox(){  

slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);  

}  

intervalId = window.setInterval(openBox,30);  

</script>

<div id="MyMoveAd" style="background:#ffffff;height:1px;overflow:hidden;">

<a href=http://brucehan.com/ target="_blank"><img src="http://brucehan.com/" border="0" width="**px(宽度)"/></a>

</div>      

<script type="text/javascript">   

slideAd(‘MyMoveAd’,5);  

</script>

第二种:自动展开收缩+手动可控版。

<script language=javascript type=text/javascript>

var hmax = 625-1;//最大高度

var hmin = 25;//最小高度

var h=0;

function addCount(){

if(h<hmax){

   h += 20;

   setTimeout("addCount()",1);

}

else {

   h=hmax;

   setTimeout("noneAds()",3000); //停留时间自己适当调整 1000 = 1秒

   document.getElementById("adsOPEN").style.display = "none";

}

document.getElementById("ads").style.display = "";

document.getElementById("ads").style.height = h+"px";

}

window.onload = function showAds(){

document.getElementById("ads").style.display = "none";

document.getElementById("ads").style.height = "0px";

addCount(); //慢慢打开

// h=hmax;

// setTimeout("noneAds()",3000); //停留时间自己适当调整 1000 = 1秒

}

function openAds(){

h = 0;//高度

addCount(); //慢慢打开

}

function noneAds(){

if(h>hmin) {

   h -= 20;

   setTimeout("noneAds()",1);

}

else {

   h = hmin;

   document.getElementById("ads").style.display = "none";

   document.getElementById("adsOPEN").style.display = "";

   return;

}

document.getElementById("ads").style.height = h+"px";

}

</script>

<DIV id=ads style="OVERFLOW: hidden; TOP: 0px; TEXT-ALIGN: center;display:none">

<IMG src="http://brucehan.com">

</DIV>

<DIV id=adsOPEN style="OVERFLOW: hidden; TEXT-ALIGN: center">

<A href="javascript:openAds()"><IMG src="http://brucehan.com" border=0></A>

</DIV>

第三种:自动展开收缩+手动可控版 伸缩广告条!

<html>

<head>

<title>伸缩广告条</title>

<script language="javascript" type="text/javascript">

<!–

var checktopAds=false;

function open_chk_show(){

if(!checktopAds){

var anim = function(){

n += 5;

if(n >= 45){

document.getElementById(‘topAds_chk_show’).style.marginTop = "0";

window.clearInterval(t1);

}

else{

document.getElementById(‘topAds_chk_show’).style.marginTop = "-"+(45 – n)+"px";

}

},n=0;

var t1 = window.setInterval(anim,80);

}

}

function close_chk_show(){

var anim = function(){

n += 5;

if(n >= 45){

document.getElementById(‘topAds_chk_show’).style.marginTop = "-45px";

window.clearInterval(t1);

}

else{

document.getElementById(‘topAds_chk_show’).style.marginTop = "-"+ n +"px";

}

},n=0;

var t1 = window.setInterval(anim,80);

}

window.onload=function(){

open_chk_show()

window.setTimeout(‘close_chk_show()’,5000)

}

//–>

</script>

<style type="text/css">

body{margin:0px; text-align:center}

div#topAds_chk_show{margin:auto; overflow:hidden; width:956px;}

img#img_navi01,img#img_navi02{border:0px;height:40px; float:left}

p{font:Arial 14px}

</style>

</head>

<body>

<div id="topAds_chk_show" style="display:block;">

<img id="img_navi01" src="**" style="width:800px;">

<img id="img_navi02" src="***" alt="关闭" style="width:52px; cursor:pointer" onclick="javascript:close_chk_show();">

</div>

<p>5秒后回缩

</body>

</html>

声明原创文章-转载请注明Bruce|http://brucehan.com/本文链接地址: 首页自动伸缩广告代码大全

Categories: Technology Tags: ,
Bruce |
  1. February 20th, 2010 at 22:55 | #1

    你这个网站比较适合用cms~

  2. February 21st, 2010 at 20:08 | #2

    @风吟 给推荐个! :smile: