两个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(){
// 标签的索引
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这个变量来引用当前滑过的li
var that=this;
// 如果存在准备执行的定时器,立刻清除,只有当前停留时间大于500ms时才开始执行
if(timers){
clearTimeout(timers);
timers=null;
}
// 延迟半秒执行
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>