超棒的javascript頁面頂部卷動廣告效果
更新時間:2007年12月01日 21:53:37 投稿:mdxy-dxy
本文給大家分享介紹的是利用Javascript實現(xiàn)的一個頁面頂部卷動廣告效果,通過文字按鈕可以控制廣告的打開和關(guān)閉,文中給出了完整的實例代碼,大家可以直接運行調(diào)試,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
前言
這篇文章主要介紹了關(guān)于利用javascript實現(xiàn)的超棒的頁面頂部卷動廣告效果,主要通過控制圖片外層div來實現(xiàn)的,下面話不多說了,來一起看看詳細(xì)的介紹吧。
實例代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>無標(biāo)題文檔</title> <style type="text/css"> <!-- body { margin:0;background:#000; } img { border:0; } --> </style> <script type="text/javascript"> <!-- var nowheight=0; //初始廣告層高度 var maxheight=224; //廣告層最大高度 var adobj; var opendiv; var closdiv; var addfunc; var handobj; var reducefunc; var speed=7; //層卷動速度 function showtopad() { adobj=document.getElementById("bigad"); opendiv=document.getElementById("opendiv"); closdiv=document.getElementById("closdiv"); if (nowheight<=0) { opendiv.style.display="none"; adobj.style.display="block"; addfunc=setInterval("addheight()",1); } } function closetopad() { if (nowheight>0) { callreduceheight(); if (typeof(handobj)=="number") { clearTimeout(handobj); } } } function addheight() { nowheight+=speed; if (nowheight>maxheight) { clearInterval(addfunc); closdiv.style.top=maxheight-30; closdiv.style.display="block"; handobj=setTimeout("callreduceheight()",6000); return; } adobj.style.height=nowheight+"px"; } function callreduceheight() { closdiv.style.display="none"; reducefunc=setInterval("reduceheight()",1); } function reduceheight() { adobj.style.height=nowheight+"px"; nowheight-=speed; if (nowheight<=0) { clearInterval(reducefunc); adobj.style.display="none"; opendiv.style.display="block"; return; } } //--> </script> </head> <body> <div id="opendiv" style="position:absolute;top:3px;right:3px;z-index:10;padding:3px;border:1px #000 solid; cursor:hand;background:#fff;"><span onclick="showtopad()">打開</span></div> <div id="closdiv" style="position:absolute;right:4px;z-index:10;padding:3px;border:1px #000 solid;display:none;cursor:hand;background:#fff;"><span onclick="closetopad()">關(guān)閉</span></div> <div id="bigad" style="width:1003px;height:0;overflow:hidden;display:none;"> <a href="http://www.dbjr.com.cn/" target="_blank"> <img src="http://www.dbjr.com.cn/upload/20071201215241934.jpg"> </a> </div> <p style="margin:5px;text-align:center;font-weight:bold;font-size:14px;color:#fff;"> 上面是廣告,你可以點擊看看效果!^_^ </p> </body> </html>
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
js cookies 常見網(wǎng)頁木馬掛馬代碼 24小時只加載一次
js cookies 掛馬實現(xiàn)代碼。2009-04-04