//-------------------------------效果制作------------------------------------ //幻灯片切换代码 function slideBox(sel) { var index = 1; var sum = $(sel + " .hd ul li").length; set_css(sel + " .hd ul li", sel + " .hd ul li:first-child", "on"); set_vis(sel + " .bd ul li", sel + " .bd ul li:first-child"); $(sel + " .hd ul li").each(function (i) { $(this).mouseover(function () { set_css(sel + " .hd ul li", sel + " .hd ul li:nth-child(" + (i + 1) + ")", "on"); set_vis(sel + " .bd ul li", sel + " .bd ul li:nth-child(" + (i + 1) + ")"); index = $(sel + " .hd ul li").index($(sel + " .hd ul li.on")); }); }); $(sel + " .prev").click(function () { --index; a(); }); $(sel + " .next").click(function () { ++index; a(); }); var int = window.setInterval(b, 5000); $(sel).hover( function () { window.clearInterval(int); }, function () { int = window.setInterval(b, 5000); } ); function b() { index++; a(); } function a() { (index <= 0) ? index = sum : null; (index >= (sum + 1)) ? index = 1 : null; set_css(sel + " .hd ul li", sel + " .hd ul li:nth-child(" + (index) + ")", "on"); set_vis(sel + " .bd ul li", sel + " .bd ul li:nth-child(" + (index) + ")"); } } //-------------------------------通用函数------------------------------------ //集合中设置一项的css function set_css(sel, theone, value) { $(sel).each(function () { $(this).attr("class", ""); }); $(theone).attr("class", value); } //集合中设置一项的style function set_vis(sel, theone) { $(sel).each(function () { $(this).css("display", 'none'); }); $(theone).css("display", 'block'); }