js面向对象插件的做法框架new goBuy('.cakeItem',{ add:'.add', reduce:'.reduce' },[1,0.7,0.6]);


/*弹窗购买蛋糕*/
;(function(){ var $DialogBg=$(".Dialogbg-Select");
var $Dialog=$(".Dialog-Select");
var $close=$(".s-closes"); function goBuy(els,opts,disArr,dis) {
this.$els = $(els);
this.$add = this.$els.find(opts.add);
this.$reduce = this.$els.find(opts.reduce);
this.num=1;
this.max=50;
this.oldPrice =0;
this.totalPrice =0;
this.newPrice =0;
this.disArr = disArr;
this.dis = dis;
this._init();
} goBuy.prototype = {
strArr:[],
add:function (ele) { },
reduce:function (ele) { },
/*价格计算*/
counts:function (ele) { },
initialize:function (ele) {
/*初始化数据*/
var self = this; }, showDialog:function () {
$DialogBg.fadeIn();
$Dialog.fadeIn();
},
close:function () {
$DialogBg.fadeOut();
$Dialog.fadeOut();
},
_init:function () {
/*事件*/
var self = this;
this.$els.click(function () {
self.initialize($(this));
}); $close.click(function () {
self.close();
});
$DialogBg.click(function () {
self.close();
});
this.$add.click(function () {
self.add($(this));
});
this.$reduce.click(function () {
self.reduce($(this));
});
}
} new goBuy('.cakeItem',{
add:'.add',
reduce:'.reduce'
},[1,0.7,0.6]); })();
 
上一篇:Multi-Projector Based Display Code ---- FAQ


下一篇:解决CSS垂直居中的几种方法(基于绝对定位,基于视口单位,Flexbox方法)