var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; }; if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } } { let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opener = _____WB$wombat$assign$function_____("opener"); $k.fn.banner = function (config) { var obj = function (selector, config) { this.selector = selector; this.config = $.extendEx({}, this.defConfig, config); } obj.prototype.defConfig = { interval: 5000, animation_duration: 900 //这个时间要与css动画定义的时间一致 //animation_name:''//动画名称 }; obj.prototype.banner = function () { var _obj = this; var itemList = _obj.selector.find('.kui-banner-item'); _obj.itemList = itemList; //底部放一条 if (_obj.selector.css('position') == 'static') { _obj.selector.css('position', 'relative'); } var bottomRow = $('
').appendTo(_obj.selector); bottomRow.css('background-color', 'rgba(0,0,0,0.6)'); bottomRow.css('width', '100%'); bottomRow.css('bottom', '0'); var btnContainer = $('').appendTo(bottomRow); $.each(itemList, function (i, item) { var btn = $('').appendTo(btnContainer); btn.click(function () { if (i == _obj.index) { return; } if (i > _obj.index) { _obj.direction = 'r_to_l'; } if (i < _obj.index) { _obj.direction = 'l_to_r'; } window.clearTimeout(_obj.timerID); window.clearInterval(_obj.intervalID); _obj.selector.find('.kui-banner-item').removeClass(_obj.config.animation_name_right_to_left); _obj.selector.find('.kui-banner-item').removeClass(_obj.config.animation_name_left_to_right); //_obj.index = i; _obj.show(i); _obj._startInterval(); }); $(item).remove(); }); _obj.btnList = _obj.selector.find('.kui-banner-btn'); _obj.index = 0;//当前显示图片. _obj.selector.append(itemList[_obj.index]); $(_obj.btnList[_obj.index]).addClass('active'); //_obj.direction = 'r_to_l'; _obj._startInterval(); } obj.prototype._startInterval=function(){ var _obj = this; _obj.direction = 'r_to_l'; _obj.intervalID = window.setInterval(function () { var playIndex; if (_obj.direction == 'r_to_l') { playIndex = (_obj.index + 1) % _obj.itemList.length; } else { playIndex = _obj.index - 1; if (playIndex < 0) { playIndex = _obj.itemList.length - 1; } } _obj.show(playIndex); }, _obj.config.interval); } obj.prototype.show = function (i) { var _obj = this; var btnList = _obj.btnList; var itemList = _obj.itemList; btnList.removeClass('active'); $(btnList[i]).addClass('active'); if (_obj.selector.find('.kui-banner-item').length > 1) { var removeItem = _obj.selector.find('.kui-banner-item:eq(0)'); removeItem.remove(); removeItem.removeClass(_obj.config.animation_name_right_to_left); removeItem.removeClass(_obj.config.animation_name_left_to_right); } var firstItem = _obj.selector.find('.kui-banner-item:eq(0)'); firstItem.css('left', 0); firstItem.css('top', 0); firstItem.css('z-index', 1); _obj.selector.append(itemList[i]); if (_obj.direction=='r_to_l') {//由右向左滚动 $(itemList[i]).css('left', _obj.selector.width()); } else{//由左向右滚动 $(itemList[i]).css('left', 0-_obj.selector.width()); } $(itemList[i]).css('top', 0); $(itemList[i]).css('z-index', 2); //$(itemList[_obj.index]).addClass(_obj.config.animation_name + '-previousSibling'); if (_obj.direction == 'r_to_l') { $(itemList[i]).addClass(_obj.config.animation_name_right_to_left); } else { $(itemList[i]).addClass(_obj.config.animation_name_left_to_right); } _obj.index = i; //animation_duration设置要等于或大于css动画定义的时间。 _obj.timerID = window.setTimeout(function () { window.clearTimeout(_obj.timerID); $(itemList[i]).removeClass(_obj.config.animation_name_right_to_left); $(itemList[i]).removeClass(_obj.config.animation_name_left_to_right); $(itemList[i]).css('left', 0); $(itemList[i]).css('top', 0); }, _obj.config.animation_duration); } var _obj = new obj($(this.jo), config || {}); _obj.banner(); return _obj; } //自动化操作 $(function () { $.each($('body').find('.kui-banner'), function (i, o) { $k(o).banner({ interval: $(o).attr('interval'), animation_duration: $(o).attr('animation_duration'), animation_name_right_to_left: $(o).attr('animation_name_right_to_left'), animation_name_left_to_right: $(o).attr('animation_name_left_to_right') }); }); }); }