$(function () { var swidth = $("#focus").width(); var len = $("#focus ul li").length; var index = 0; var pictimer; var btn = "
"; for (var i = 0; i < len; i++) { btn += ""; } btn += "
"; $("#focus").append(btn); $("#focus .btnbg").css("opacity", 0); $("#focus .btn span").css("opacity", 0.4).mouseenter(function () { index = $("#focus .btn span").index(this); showpics(index); }).eq(0).trigger("mouseenter"); $("#focus .prenext").css("opacity", 0.0).hover(function () { $(this).stop(true, false).animate({ "opacity": "0.5" }, 300); }, function () { $(this).stop(true, false).animate({ "opacity": "0" }, 300); }); $("#focus .pre").click(function () { index -= 1; if (index == -1) { index = len - 1; } showpics(index); }); $("#focus .next").click(function () { index += 1; if (index == len) { index = 0; } showpics(index); }); $("#focus ul").css("width", swidth * (len)); $("#focus").hover(function () { clearinterval(pictimer); }, function () { pictimer = setinterval(function () { showpics(index); index++; if (index == len) { index = 0; } }, 2800); }).trigger("mouseleave"); function showpics(index) { var nowleft = -index * swidth; $("#focus ul").stop(true, false).animate({ "left": nowleft }, 300); $("#focus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300); } });