在<body>中加入onLoad="initVar(); moveBanner()"
以下代码加入<head>区域或者想调用的地方加:
- <style type="text/css">
- <!--
- #addbox {
- position: relative;
- width: 500px;
- height: 70 px;
- clip: rect(0px, 500px, 0px, 70px);
- overflow: hidden;
- }
- #banner1 {
- position: relative;
- width: 480px;
- height: 60px;
- left: 0;
- top: 5px;
- }
- #banner2 {
- position: relative;
- width: 480px;
- height: 60px;
- left: 500px;
- top: -55px !important;
- top:-58px;
- }
- -->
- </style>
- <script type="text/javascript">
- <!--
-
- var displayTime, speed, wait, banner1, banner2, link1, link2, bannerIndex, bannerLocations, bannerURLs;
- function initVar() {
- displayTime = 10; // The amount of time each banner will be displayed in seconds.
- speed = 5; // The speed at which the banners is moved (1 - 10, anything above 5 is not recommended).
- wait = true;
- banner1 = document.getElementById("banner1");
- banner2 = document.getElementById("banner2");
- link1 = document.getElementById("link1");
- link2 = document.getElementById("link2");
- banner1 = document.getElementById("banner1");
- banner2 = document.getElementById("banner2");
- banner1.style.left = 0;
- banner2.style.left = 500;
- bannerIndex = 1;
- /* Important: In order for this script to work properly, please make sure that the banner graphic and the
- URL associated with it have the same index in both, the bannerLocations and bannerURLs arrays.
- Duplicate URLs are permitted. */
- // Enter the location of the banner graphics in the array below.
- bannerLocations = new Array("www.twinsworld.org/jsimg/pic1.jpg","www.twinsworld.org/jsimg/pic2.jpg","www.twinsworld.org/jsimg/pic3.jpg","www.twinsworld.org/jsimg/pic4.jpg","www.twinsworld.org/jsimg/pic5.jpg");
- // Enter the URL's to which the banners will link to in the array below.
- bannerURLs = new Array("http://www.twinsworld.org","http://www.twinsworld.org","http://www.twinsworld.org","http://www.twinsworld.org","http://www.twinsworld.org");
- }
- function moveBanner(){
- if(!wait){
- banner1.style.left = parseInt(banner1.style.left) - (speed * 5);
- banner2.style.left = parseInt(banner2.style.left) - (speed * 5);
- if(parseInt(banner1.style.left) <= -500){
- banner1.style.left = 500;
- bannerIndex = (bannerIndex < (bannerLocations.length - 1)) ? ++bannerIndex :0;
- banner1.src = bannerLocations[bannerIndex];
- link1.href = bannerURLs[bannerIndex];
- wait = true;
- }
- if(parseInt(banner2.style.left) <= -500){
- banner2.style.left = 500;
- bannerIndex = (bannerIndex < (bannerLocations.length - 1)) ? ++bannerIndex :0;
- banner2.src = bannerLocations[bannerIndex];
- link2.href = bannerURLs[bannerIndex];
- wait = true;
- }
- setTimeout("moveBanner()",100);
- } else {
- wait = false;
- setTimeout("moveBanner()", displayTime * 1000);
- }
- }
- -->
- </script>
复制代码
以下代码加入想实现的区域:
- <div align="center">
- <div name="addbox" id="addbox">
- <a name="link1" id="link1" href="www.twinsworld.org"><img border="0" name="banner1"
- id="banner1" src="www.twinsworld.org/jsimg/pic1.jpg"></a>
- <a name="link2" id="link2" href="www.twinsworld.org"><img border="0" name="banner2"
- id="banner2" src="www.twinsworld.org/jsimg/pic2.jpg"></a>
- </div></div>
复制代码 |