function Banner (containerId,isAutoAddNavigator,speed) { this.This = this; this.containerId = containerId; this.duration = speed; this.autoNavigator = isAutoAddNavigator; this.currentBannerIndex = 0; this.maxBannerIndex = $(this.containerId + " .banner_item").length; this.timer; } Banner.prototype.initBanner = function () { var This = this; $(This.containerId + " .banner_item").eq(0).addClass("banner_active"); this.timer = setInterval(function () { This.setCurrentBanner(); },This.duration); if (this.autoNavigator) { this.autoAddNavigators(); } //绑定指示器 hover 事件 //hover后 停止轮播 否则继续 $(this.containerId + " .navigator_item").hover(function () { clearInterval(This.timer); This.timer = null; },function () { if (This.timer == null) { This.timer = setInterval(function () { This.setCurrentBanner(); },This.duration); } }) //绑定指示器 click 事件 //click后 停止轮播 跳转到指定index $(This.containerId + " .navigator_item").click(function () { var index = $(this).index(); This.currentBannerIndex = index; This.setCurrentBanner(); }) } Banner.prototype.autoAddNavigators = function () { var itemCount = $(this.containerId + " .banner_item").length; for (var i = 0;i < itemCount;i++) { if (i == 0) { $("").appendTo(this.containerId + " .navigator_list"); }else{ $("").appendTo(this.containerId + " .navigator_list"); } } } Banner.prototype.setCurrentBanner = function () { var This = this; $(This.containerId + " .banner_active").removeClass("banner_active"); $(This.containerId + " .banner_item").eq(This.currentBannerIndex).addClass("banner_active"); $(This.containerId + " .navigator_item_active").removeClass("navigator_item_active"); $(This.containerId + " .navigator_item").eq(This.currentBannerIndex).addClass("navigator_item_active"); This.currentBannerIndex++; if (This.currentBannerIndex >= This.maxBannerIndex) { This.currentBannerIndex = 0; } }