當前位置:軟件學堂 > 資訊首頁 > 網絡編程 > 編程其他 > 帶鏈接的滾動字幕代碼怎么寫

帶鏈接的滾動字幕代碼怎么寫

2012/10/29 11:33:37作者:佚名來源:網絡

移動端

【實例名稱】

帶鏈接的滾動字幕

【實例描述】

滾動文本是新聞顯示的重要手段,如果要在滾動的文本中實現鏈接,則需要動態設置鏈接文本和鏈接地址。本例學習如何實現帶鏈接的滾動字幕。

【實例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>標題頁-學無憂(www.yzddtk.cn)</title> </head> <body> <script language="JavaScript1.2"> var marqueewidth=400  //設置marquee的寬度 (in pixels) var marqueeheight=20  //設置marquee的高度 (in pixels, 該參數只適用于Netscape) var speed=4           //設置marquee滾動的速度(數值越大速度越快) //設置marquee顯示內容,使用標準的HTML語法。 var marqueecontents='<strong><big>歡迎支持中國搜索引擎 <a href="http://www.baidu.com">百度一下</a> 找到自己想找的 信息</big></strong></font>' if (document.all) document.write('<marquee scrollAmount='+speed+' style="width:'+marqueewidth+'">'+marqueecontents+'</marquee>') function regenerate(){     window.location.reload();                     //重新加載頁面 } function regenerate2(){     if (document.layers){     setTimeout("window.onresize=regenerate",450); //窗體改變大小時重載     intializemarquee();     } } function intializemarquee(){    //使用nobr控制顯示的字符個數     document.cmarquee01.document.cmarquee02.document. write('<nobr>'+marqueecontents+'</nobr>');     document.cmarquee01.document.cmarquee02.document.close();     thelength=document.cmarquee01.document. cmarquee02.document.width;  //獲取層的寬度     scrollit();                                                        //實現字體的滾動 } function scrollit(){         if (document.cmarquee01.document.cmarquee02 .left>=thelength*(-1)){         document.cmarquee01.document.cmarquee02.left-=speed;         setTimeout("scrollit()",100);                       //定時器實現不停的調用     }     else{         document.cmarquee01.document.cmarquee02.left=marqueewidth;         scrollit();     } } window.onload=regenerate2; </script> <ilayer width=&{marqueewidth}; height=&{marqueeheight}; name="cmarquee01"> <layer name="cmarquee02"></layer> </ilayer> </body> </html>

【運行效果】

運行效果

【難點剖析】

本例的重點主要包括如何動態添加鏈接和如何實現文本的滾動=代碼中使用了一個全局變量“marqueecontents來保存鏈接內容和地址:文本的滾動通過定時器不斷地調用“scrollit”方法實現。

【源碼下載】

如果你不愿復制代碼及提高代碼準確性,你可以點擊:帶鏈接的滾動字幕 進行本實例源碼下載 

標簽: 鏈接    

欧美一级一极性活片免费观看,欧美一级艳片欧美精品,欧美一级性爱大片,欧美一级囗交视频 视频,欧美一级特黄录像视频