var innerGroup = $(".innerwraper"); var leftArrow = $(".left-arrow"); var rightArrow = $(".right-arrow"); var spanGroup = $(".pagination span"); //var imgWidth = $(".innerwraper img:first-child").eq(0).width(); var imgWidth = 337; var _index = 0; var timerSBanner = null; var flag = true; rightArrow.on("click", function() { //右箭头 flag = false; clearInterval(timerSBanner); _index++; selectPic(_index); }) leftArrow.on("click", function() { //左箭头 flag = false; clearInterval(timerSBanner); if (_index == 0) { _index = innerGroup.length - 1; $(".inner").css("left", -(innerGroup.length - 1) * imgWidth); } _index--; selectPic(_index); }) spanGroup.on("click", function() { //导航切换 _index = spanGroup.index($(this)); selectPic(_index); }) $(".container").hover(function() { //鼠标移入 clearInterval(timerSBanner); flag = false; }, function() { flag = true; timerSBanner = setInterval(go, 5000); }); function autoGo(bol) { //自动行走 if (bol) { timerSBanner = setInterval(go, 5000); } } setTimeout("autoGo("+flag+")",100); function go() { //计时器的函数 _index++; if(_index < 0 || _index >= innerGroup.length){ _index = 0; } selectPic(_index); } function selectPic(num) { $(".pagination span").eq(num).addClass("active").siblings().removeClass("active"); $(".index-main-box .index-main .focus-news .sbanner-title label").hide(); $(".index-main-box .index-main .focus-news .sbanner-title #flag"+(num+1)).show(); $(".inner").animate({ left: -num * imgWidth, }, 1000, function() { //检查是否到最后一张 if (_index == innerGroup.length - 1) { _index = -1; //$(".inner").css("left", "0px"); //$(".pagination span").eq(0).addClass("active").siblings().removeClass("active"); } }) }