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è)置時(shí)間,本每隔多長(zhǎng)時(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í)間,本每隔多長(zhǎng)時(shí)間改變廣告條中的GIF
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JS實(shí)現(xiàn)關(guān)閉小廣告特效
- js實(shí)現(xiàn)左右兩側(cè)浮動(dòng)廣告
- 基于JavaScript實(shí)現(xiàn)淘寶商品廣告效果
- 用js屏蔽被http劫持的浮動(dòng)廣告實(shí)現(xiàn)方法
- JS使用cookie實(shí)現(xiàn)只出現(xiàn)一次的廣告代碼效果
- JavaScript實(shí)現(xiàn)彈出廣告功能
- 原生js實(shí)現(xiàn)網(wǎng)頁(yè)頂部自動(dòng)下拉/收縮廣告效果
- JavaScript實(shí)現(xiàn)廣告彈窗效果
- JavaScript cookie 跨域訪問之廣告推廣
- JS前端廣告攔截實(shí)現(xiàn)原理解析
相關(guān)文章
將Sublime Text 3 添加到右鍵中的簡(jiǎn)單方法
下面小編就為大家分享一篇將Sublime Text 3 添加到右鍵中的簡(jiǎn)單方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12
JavaScript微信定位功能實(shí)現(xiàn)方法
這篇文章主要介紹了JavaScript微信定位功能實(shí)現(xiàn)方法,將定位到的經(jīng)緯度轉(zhuǎn)換為百度地圖對(duì)應(yīng)的經(jīng)緯度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
學(xué)習(xí)JavaScript設(shè)計(jì)模式之代理模式
這篇文章主要為大家介紹了JavaScript設(shè)計(jì)模式中的狀態(tài)模式,對(duì)JavaScript設(shè)計(jì)模式感興趣的小伙伴們可以參考一下2016-01-01
javascript設(shè)置和獲取cookie的方法實(shí)例詳解
這篇文章主要介紹了javascript設(shè)置和獲取cookie的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析總結(jié)了JavaScript操作cookie簡(jiǎn)單實(shí)現(xiàn)數(shù)據(jù)存儲(chǔ)與讀取的相關(guān)技巧,需要的朋友可以參考下2016-01-01
js實(shí)現(xiàn)圖片淡入淡出切換簡(jiǎn)易效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)圖片淡入淡出切換簡(jiǎn)易效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
JavaScript 設(shè)計(jì)模式 富有表現(xiàn)力的Javascript(一)
javascript設(shè)計(jì)模式是圖靈出版,學(xué)習(xí)中力求每個(gè)章節(jié)都細(xì)看。2010-05-05

