javascript實(shí)現(xiàn)循環(huán)廣告條效果
更新時間:2017年12月12日 10:32:05 作者:shursulei
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)循環(huán)廣告條效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了javascript實(shí)現(xiàn)循環(huán)廣告條的具體代碼,供大家參考,具體內(nèi)容如下
html代碼:
<!DOCTYPE html> <html> <head> <title>Rotating Banner</title> <script src="script07.js"></script> <link rel="stylesheet" href="script01.css" rel="external nofollow" > </head> <body> <div class="centered"> <img src="images/reading1.gif" id="adBanner" alt="Ad Banner"> </div> </body> </html>
css代碼:
body { background-color: white; color: black; font-size: 20px; font-family: "Lucida Grande", Verdana,Arial, Helvetica, sans-serif; } h1, th { font-family: Georgia, "Times New Roman",Times, serif; } h1 { font-size: 28px; } table { border-collapse: collapse; } th, td { padding: 10px; border: 2px #666 solid; text-align: center; width: 20%; } #free, .pickedBG { background-color: #f66; } .winningBG { background-image:url(images/redFlash.gif); }
js代碼:
window.onload = rotate; var thisAd = 0; function rotate() { var adImages = new Array("images/ reading1.gif","images/reading2. gif","images/reading3.gif"); thisAd++; if (thisAd == adImages.length) { thisAd = 0; } document.getElementById("adBanner").src = adImages[thisAd]; setTimeout(rotate, 3 * 1000);//設(shè)置時間,本每隔多長時間改變廣告條中的GIF }
在循環(huán)廣告條中添加鏈接:修改js的代碼
window.onload = initBannerLink; var thisAd = 0; function initBannerLink() { if (document.getElementById("adBanner").parentNode.tagName == "A") { document.getElementById("adBanner").parentNode.onclick = newLocation; } rotate(); } function newLocation() { var adURL = new Array("negrino.com","sun.com","microsoft.com"); document.location.href = "http://www." + adURL[thisAd]; return false; } function rotate() { var adImages = new Array("images/ reading1.gif","images/reading2. gif","images/reading3.gif"); thisAd++; if (thisAd == adImages.length) { thisAd = 0; } document.getElementById("adBanner").src = adImages[thisAd]; setTimeout(rotate, 3 * 1000);//設(shè)置時間,本每隔多長時間改變廣告條中的GIF }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- JS實(shí)現(xiàn)關(guān)閉小廣告特效
- js實(shí)現(xiàn)左右兩側(cè)浮動廣告
- 基于JavaScript實(shí)現(xiàn)淘寶商品廣告效果
- 用js屏蔽被http劫持的浮動廣告實(shí)現(xiàn)方法
- JS使用cookie實(shí)現(xiàn)只出現(xiàn)一次的廣告代碼效果
- JavaScript實(shí)現(xiàn)彈出廣告功能
- 原生js實(shí)現(xiàn)網(wǎng)頁頂部自動下拉/收縮廣告效果
- JavaScript實(shí)現(xiàn)廣告彈窗效果
- JavaScript cookie 跨域訪問之廣告推廣
- JS前端廣告攔截實(shí)現(xiàn)原理解析
相關(guān)文章
javascript中return,return true,return false三者的用法及區(qū)別
這篇文章主要介紹了javascript中return,return true,return false三者的用法及區(qū)別的相關(guān)資料,需要的朋友可以參考下2015-11-11JS實(shí)現(xiàn)直接運(yùn)行html代碼的方法
這篇文章主要介紹了JS實(shí)現(xiàn)直接運(yùn)行html代碼的方法,涉及javascript窗口操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-03-03