韶华_易逝
2018-09-27 16:53
var rating = (function () {
// 点亮整颗
var LightEntire = function (el, options) {
this.$el = $(el);
this.$itme = this.$el.find(".rating-item");
this.opts = options;
};
LightEntire.phototype.init = function () {
this.LightOn(this.opts.num);
this.bindEvent();
};
LightEntire.phototype.LightOn = function (num) {
num = parseInt(num);
this.$itme.each(function (index) {
if (index<num) {
$(this).css("background-color","yellow");
}else{
$(this).css("background-color","#EEE");
}
})
};
LightEntire.phototype.bindEvent = function () {
var self = this;
this.$el.on("mouseover",".rating-item",function () {
self.LightOn($(this).index() + 1);
}).on("click",".rating-item",function () {
self.opts.num = $(this).index() + 1;
}).on("mouseout",function () {
self.LightOn(self.opts.num);
})
};
// 默认参数
var defaults = {
num: 0,
readOnly: false,
select: function () {},//鼠标移入的方法
chosen: function () {}//鼠标点击的方法
}
// 初始化
var init = function (el, options) {
options = $.extend({}, defaults, options);
new LightEntire(el, options).init();
};
return {
init: init
};
})();
rating.init("#rating",{
num: 2,
});
吧 phototype 改成 prototype
星级评分原理和实现(上)
25809 学习 · 109 问题
相似问题