时间:2021-07-01 10:21:17 帮助过:4人阅读
本文实例为大家分享了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> <p class="centered"> <img src="images/reading1.gif" id="adBanner" alt="Ad Banner"> </p> </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 }
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
如何利用滚动条位置判断
使用微信小程序如何实现动态设置placeholder提示文字
有关ES6/JavaScript使用技巧(详细教程)
在nodejs中如何实现爬取网站图片
以上就是在javascript中如何实现循环广告条的详细内容,更多请关注Gxl网其它相关文章!