var showindex = 1; function showbg(src) { var index = $("#flashs .btn span").index($("#flashs .btn span.cur")); if (index < 0) { index = 0; } $("#flashs .btn span.cur").css("opacity", 0.7).removeclass("cur"); $("#flashbg" + index).css({"opacity":0,"z-index":1}); $("#flashbg" + showindex).css({ "z-index": 2 }); $("#flashbg" + showindex).animate({ opacity: 1 }, 500); $("#flashs .btn span").eq(showindex).css("opacity", 1).addclass("cur"); } var h = $("#flashs div.bgitem").css("opacity", 0).length; var btn = "
"; for (var i = 0; i < h; i++) { btn += "" + (i + 1) + ""; } btn += "
"; $("#flashs").append(btn); $("#flashs .btn span").css("opacity", 0.7).mouseenter(function () { showindex = $("#flashs .btn span").index(this); showbg(showindex); }).eq(0).trigger("mouseenter"); $("#flashs").hover(function () { clearinterval(pictimer); }, function () { pictimer = setinterval(function () { showindex++; if (showindex == h) { showindex = 0; } showbg(showindex); }, 5000) }).eq(0).trigger("mouseleave");