欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javascript实现循环广告条效果

程序员文章站 2022-06-25 14:40:37
本文实例为大家分享了javascript实现循环广告条的具体代码,供大家参考,具体内容如下 html代码: <...

本文实例为大家分享了javascript实现循环广告条的具体代码,供大家参考,具体内容如下

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);//设置时间,本每隔多长时间改变广告条中的gif
}

在循环广告条中添加链接:修改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);//设置时间,本每隔多长时间改变广告条中的gif
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。