$(function () { //banner ;(function(){ var $pic = $('.pic li'), $btn = $('.btn li'), index = 0, length = $pic.length; var timer; $btn.eq(index).addClass('on'); $pic.eq(index).show(); $btn.click(function () { index = $(this).index(); fn() }); auto(); function auto() { timer = setInterval(function (){ index = ++index%length; fn() },5000) } function fn() { $btn.eq(index).addClass('on').siblings().removeClass('on'); $pic.eq(index).fadeIn().siblings().fadeOut(); } })(); //newsBanner (function(){ var $pic = $('.new-pic li'), $btn = $('.new-btn li'), $title = $('.new-title li'), $span = $('.new-pn span'), index = 0, timer, length = $pic.length; $pic.eq(index).show(); $title.eq(index).show(); $btn.eq(index).addClass('on'); $btn.click(function () { index = $(this).index(); fn() }); $span.click(function () { //console.log($(this).index()) if( $(this).index() ){ index = ++index%length; fn() }else { index = --index%length; fn() } }); auto(); function auto() { timer = setInterval(function () { index = ++index%length; fn() },3000) }; function fn() { $btn.eq(index).addClass('on').siblings().removeClass('on'); $pic.eq(index).fadeIn().siblings().fadeOut(); $title.eq(index).fadeIn().siblings().fadeOut(); } })(); (function(){ var navshow = $('.navshow'), nav = $('.nav'); navshow.click(function(){ nav.slideToggle() }) })() });