$(function(){ $('.index_tt .banner_txt').eq(0).show().siblings().hide(); var $ct=$('.banner_box ul'), $items=$ct.children(), $pre=$('.index_pre'), $next=$('.banner_next'), imgCount=$items.length, imgWidth=$items.width(); $ct.append($items.first().clone()); $ct.prepend($items.last().clone()); var newCount=$ct.children().length; $ct.css({marginLeft:0-imgWidth,width:newCount*imgWidth}); $next.on('click',function(){ playnext(); }) $pre.on('click',function(){ playpre(); }) var curidx =0; var mov = 1; var lock=false; function playnext(){ $ct.animate({marginLeft:'-='+mov*imgWidth},function(){ curidx++; if(curidx===imgCount){ $ct.css({marginLeft:0-imgWidth}); curidx=0; } }) $('.index_tt .banner_txt').eq(curidx).show().siblings().hide(); } function playpre(){ $ct.animate({marginLeft:'+='+mov*imgWidth},function(){ curidx--; if(curidx===(-1)){ $ct.css({marginLeft:0-imgWidth*imgCount}); curidx=3; } }) $('.index_tt .banner_txt').eq(curidx).show().siblings().hide(); } var timer=setInterval(playnext,3000) $('.banner').mouseenter(function(){ clearInterval(timer) }) $('.banner').mouseleave(function(){ timer=setInterval(playnext,3000) }) $('.img_list ol li').hover(function(){ var simg = $(this).children('img').attr('src') $('.banner_box ul li').eq(curidx+1).find('img').attr('src',simg) }) //导航 $(window).scroll(function(){ var scrolltop=$(document).scrollTop() if(scrolltop>400){ $('header').addClass('h_fix') $('body').css({paddingTop:'74px'}) }else{ $('header').removeClass('h_fix') $('body').css({paddingTop:0}) } }); })