您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)如何使用javascript實(shí)現(xiàn)循環(huán)廣告條效果的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
具體內(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; } h2, th { font-family: Georgia, "Times New Roman",Times, serif; } h2 { 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è)置時(shí)間,本每隔多長時(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è)置時(shí)間,本每隔多長時(shí)間改變廣告條中的GIF }
感謝各位的閱讀!關(guān)于“如何使用javascript實(shí)現(xiàn)循環(huán)廣告條效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。