/** * 两侧广告js * author:zhangzj; * v 1.0.1 * 2015-12-29 * */ (function(win, $) { var defaultsettings = { // 浮动元素dom dom: null, // 广告宽度 width: 100, // 广告高度 height: 100, // 初始距顶部的高度 stop: 25, // 关闭按钮 closedom: '.close' }; win.movead = function(opts) { // 参数整合 this.cfg = $.extend({}, defaultsettings, opts); // 初始化函数 this._initevent(); }; $.extend(movead.prototype, { _initevent: function() { var c = this.cfg; var self = $(c.dom); var sh = $(window).scrolltop(); self.find('.move-item').each(function(index) { $(this).height(c.height); if(index==0 || index%2==0) { $(this).addclass('pl'); var h = sh + c.stop+(c.stop + c.height)*(parseint((index+1)/2)); $(this).offset({top:h}); }else { $(this).addclass('pr'); var h = sh + c.stop+(c.stop + c.height)*(parseint((index+1)/2)-1); $(this).offset({top:h}); } $(this).find(c.closedom).on("click",function(){ $(this).parent().addclass('hidden'); for (var j = 2 ; index + j < self.find('.move-item').length; j += 2) { var n = self.find('.move-item').eq(index + j); var nsh = $(window).scrolltop(); var nh = n.offset().top - (c.stop+c.height+nsh); n.animate({top:nh},1000); } }); }); } }); }(this, jquery));