$(function() { // 首页轮播 (function() { var sup = $("#banner"), // 图片 pics = sup.find(".pics li"), curr_p = pics.eq(0), next_p = null, // 下标 idxs = sup.find(".idxs li"), curr_i = idxs.eq(0), next_i = null, // 按钮 left = sup.find(".btns .left"), right = sup.find(".btns .right"), // 记录切换 idx = 0, idx_m = pics.length-1, tt = 0, delay = 5000; // 初始化 $(window).on("load", function() { idxs.hover(idxhoveron, function(){}); sup.hover(banhoveron, banhoverout); left.on("click", function(){btnclick(idxdec());}); right.on("click", function(){btnclick(idxinc());}); auto(); }); // 自动切换控制 function auto() { tt = settimeout(function() { fade(idxinc()); }, delay); } // 切换控制 function fade(i) { cleartimeout(tt); curr_p.stop(false, true).fadeout(500); curr_p = next_p = pics.eq(i).stop(false, true).fadein(); curr_i.removeclass("on"); curr_i = next_i = idxs.eq(i).addclass("on"); auto(); } // idx递增递减 function idxinc() { return idx===idx_m? idx=0: ++idx; } function idxdec() { return idx===0? idx=idx_m: --idx; } // 左右按钮唤出控制 function banhoveron() { left.stop().animate({"left":100}, 152); right.stop().animate({"right":100}, 152); } function banhoverout() { left.stop().animate({"left":-52}); right.stop().animate({"right":-52}); } // 按钮点击控制 function btnclick(i) { fade(i); } // 下标hover控制 function idxhoveron(elem) { cleartimeout(tt); idx = $(this).index(); fade(idx); } })(); (function() { var sup = $('.navgation'), navs = $("#nav li"), navs_1 = navs.filter('.n1'), navs_2 = navs_1.siblings(), items = $('#subnavs .innerwrapper div'), curr_i = $(), opened = false, tt = 0; navs_2.hover(function(idx) { cleartimeout(tt); idx = $(this).index()-1; if (!opened) { sup.stop(false).animate({'height':90}, {'duration':300, 'easing':'easeinoutquint'}); opened = true; } curr_i.stop(false,true).fadeout(300); curr_i = items.eq(idx).stop(false, true).fadein(300); }, function() { tt = settimeout(slideup, 300); }); items.hover(function() { cleartimeout(tt); }, function() { tt = settimeout(slideup,300); }) navs_1.hover(slideup); function slideup() { sup.stop(false).animate({'height':44}, {'duration':300, 'easing':'easeinoutquint'}); opened = false; } }()); // 栏目滑动 (function() { var sup = $('#items .innerwrapper'), // 容器 container = sup.find('dl'), items = container.find('dd'), item0 = items.eq(0), items_w = item0.width()+parseint(item0.css('margin-right')), item0 = null, items_l = items.length, // 按钮 left = sup.find('.btnprev'), right = sup.find('.btnnext'), // 变量记录 idx = 0, idx_m = items_l - 3; //odd:填充背景色 // container.find('dd:odd').css({"background":"#e7d9a9"}); // 鼠标经过,左右按钮淡进淡出 sup.hover(function(){ left.stop(false,true).fadein(); right.stop(false,true).fadein(); }).parent().hover(function(){ },function(){ left.stop(false,true).fadeout(); right.stop(false,true).fadeout(); }); var i = 0; container.find('dd:eq(0)').find(".link2").css("cursor","pointer"); container.find('dd').append("
"); // container.find('dd').each(function() { // $(this).append("
"); // }); container.find('dd').hover(function(){ $(this) .find(".mask") .stop(false,true) .fadein() .siblings(".link1") .stop(true,false).animate({left:35+"px",opacity:1}) .siblings(".link2") .stop(true,false).animate({right:35+"px",opacity:1}) },function(){ $(".link1").stop(true,false).animate({left:0+"px",opacity:0}); $(".link2").stop(true,false).animate({right:0+"px",opacity:0}); $(".mask").stop(false,true).fadeout(); }) }()); //新闻滚动 function news_scroll(){ var nb = $(".inews_box"), ul = nb.find('ul'), up = $(".news_btn .up"), down = $(".news_btn .down"), idx = 1, delay = 4000, speed = 300, len = nb.find("li").length, maxtop = - (len-1)*46; nb.hover(function(){ clearinterval(autoplay); },function(){ autoplay = setinterval(ap,delay); }).trigger('mouseleave'); up.on('click',function(){ clearinterval(autoplay); if(idx == 1){ idx = len; ul.animate({margintop:'+=46px'},speed,function(){ ul.css({margintop:maxtop}); }); }else{ idx --; ul.stop(false,true).animate({margintop:'+=46px'},speed); } autoplay = setinterval(ap,delay); return false; }); down.on('click',function(){ clearinterval(autoplay); if(idx == len){ idx = 1; ul.animate({margintop:'-=46px'},speed,function(){ ul.css({margintop:'0'}); }); }else{ idx++; ul.stop(false,true).animate({margintop:'-=46px'},speed); } autoplay = setinterval(ap,delay); return false; }); function ap(){ idx++; if(idx<=len){ ul.stop().animate({margintop:'-=46px'},speed); }else{ idx = 1; ul.animate({margintop:'-=46px'},speed,function(){ ul.css({margintop:'0'}); }); } }; }; news_scroll();//新闻滚动 });