兩個js放在一起只有下面那個起作用,不知道那里沖突,求大神解決啊???
<script type="text/javascript">
/*1、banner廣告js*/
window.onload=banners;
function banners() {
? ? ? ? ? ? var banner = document.getElementById('banner');
? ? ? ? ? ? var list = document.getElementById('list');
? ? ? ? ? ? var buttons = document.getElementById('buttons').getElementsByTagName('span');
? ? ? ? ? ? var prev = document.getElementById('prev');
? ? ? ? ? ? var next = document.getElementById('next');
? ? ? ? ? ? var index = 1;
? ? ? ? ? ? var len = 4;
? ? ? ? ? ? var animated = false;
? ? ? ? ? ? var interval = 3000;
? ? ? ? ? ? var timer;
? ? ? ? ? ? function animate (offset) {
? ? ? ? ? ? ? ? if (offset == 0) {
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? animated = true;
? ? ? ? ? ? ? ? var time = 300;
? ? ? ? ? ? ? ? var inteval = 10;
? ? ? ? ? ? ? ? var speed = offset/(time/inteval);
? ? ? ? ? ? ? ? var left = parseInt(list.style.left) + offset;
? ? ? ? ? ? ? ? var go = function (){
? ? ? ? ? ? ? ? ? ? if ( (speed > 0 && parseInt(list.style.left) < left) || (speed < 0 && parseInt(list.style.left) > left)) {
? ? ? ? ? ? ? ? ? ? ? ? list.style.left = parseInt(list.style.left) + speed + 'px';
? ? ? ? ? ? ? ? ? ? ? ? setTimeout(go, inteval);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? ? ? list.style.left = left + 'px';
? ? ? ? ? ? ? ? ? ? ? ? if(left>-200){
? ? ? ? ? ? ? ? ? ? ? ? ? ? list.style.left = -1002 * len + 'px';
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? if(left<(-1002 * len)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? list.style.left = '-1002px';
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? animated = false;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? go();
? ? ? ? ? ? }
? ? ? ? ? ? function showButton() {
? ? ? ? ? ? ? ? for (var i = 0; i < buttons.length ; i++) {
? ? ? ? ? ? ? ? ? ? if( buttons[i].className == 'on'){
? ? ? ? ? ? ? ? ? ? ? ? buttons[i].className = '';
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? buttons[index - 1].className = 'on';
? ? ? ? ? ? }
? ? ? ? ? ? function play() {
? ? ? ? ? ? ? ? timer = setTimeout(function () {
? ? ? ? ? ? ? ? ? ? next.onclick();
? ? ? ? ? ? ? ? ? ? play();
? ? ? ? ? ? ? ? }, interval);
? ? ? ? ? ? }
? ? ? ? ? ? function stop() {
? ? ? ? ? ? ? ? clearTimeout(timer);
? ? ? ? ? ? }
? ? ? ? ? ? next.onclick = function () {
? ? ? ? ? ? ? ? if (animated) {
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (index == 4) {
? ? ? ? ? ? ? ? ? ? index = 1;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? index += 1;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? animate(-1002);
? ? ? ? ? ? ? ? showButton();
? ? ? ? ? ? }
? ? ? ? ? ? prev.onclick = function () {
? ? ? ? ? ? ? ? if (animated) {
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (index == 1) {
? ? ? ? ? ? ? ? ? ? index = 4;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? index -= 1;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? animate(1002);
? ? ? ? ? ? ? ? showButton();
? ? ? ? ? ? }
? ? ? ? ? ? for (var i = 0; i < buttons.length; i++) {
? ? ? ? ? ? ? ? buttons[i].onclick = function () {
? ? ? ? ? ? ? ? ? ? if (animated) {
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(this.className == 'on') {
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? var myIndex = parseInt(this.getAttribute('index'));
? ? ? ? ? ? ? ? ? ? var offset = -1002 * (myIndex - index);
? ? ? ? ? ? ? ? ? ? animate(offset);
? ? ? ? ? ? ? ? ? ? index = myIndex;
? ? ? ? ? ? ? ? ? ? showButton();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? banner.onmouseover = stop;
? ? ? ? ? ? banner.onmouseout = play;
? ? ? ? ? ? play();
}
/*2、tab切換js*/
function $(id){
return typeof id==='string'?document.getElementById(id):id;
}
window.onload=tabs;
function tabs(){
? // 標(biāo)簽的索引
? var indexs=0;
? var timers=null;
? var lis=$('cont2-menu').getElementsByTagName('li'),divs=$('cont2-cont').getElementsByTagName('div');
? if(lis.length!=divs.length) return;
? // 遍歷所有的頁簽
? for(var x=0;x<lis.length;x++){
? ? lis[x].id=x;
? ? lis[x].onmouseover=function(){
? ? ? // 用that這個變量來引用當(dāng)前滑過的li
? ? ? var that=this;
? ? ? // 如果存在準(zhǔn)備執(zhí)行的定時器,立刻清除,只有當(dāng)前停留時間大于500ms時才開始執(zhí)行
? ? ? if(timers){
? ? ? ? clearTimeout(timers);
? ? ? ? timers=null;
? ? ? }
? ? ? // 延遲半秒執(zhí)行
? ? ? timers=window.setTimeout(function(){
? ? ? ? for(var z=0;z<lis.length;z++){
? ? ? ? ? lis[z].className='';
? ? ? ? ? divs[z].style.display='none';
? ? ? ? }
? ? ? ? lis[that.id].className='select';
? ? ? ? divs[that.id].style.display='block';
? ? ? },100);
? ? }
? }
}
</script>