星级评分

星级评分插件

  • 直接上图先看为主:

图片描述

  • 具体代码呈现:
html部分:
CSS部分:
/*网页的全局样式 解决兼容问题*/
body,div,p,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,table,tr,td,form,input,select,textarea,span,img,a,em,strong,*{ margin:0; padding:0;}
body{ font-family:"宋体"; font-size:12px; color:#000000;}
ul,ol,li{ list-style:none;}
h1,h2,h3,h4,h5,h6{ font-size:14px;}
input,select,textarea{ vertical-align:middle;}
img{ border:none; vertical-align:middle;}
a{ text-decoration:none; color:#333333;}
a:hover{ color:#009999;}
.clear{ clear:both; height:0px; width:0px; overflow:hidden;}

body{
    background: #666;
}
.wrap-star,.wrap-star2{
    width: 105px;
    height: 21px;
    margin: 100px auto;
}
.inner-star{
    width: 21px;
    height: 21px;
    float: left;
    background: url("commstar.png") no-repeat 0 -21px;
    cursor: pointer;
}
JS部分:
//此部分用到了sea.js所以要特别注意一下

    
//default.js部分:
define(function(require,exports,module){
    //当前目录
    var $ = require("./jquery.js");
    

    $(()=>{

        var StarProduct=(function(){

        var extend=function(childClass,parentClass){
            var B=function(){};
            B.prototype=parentClass.prototype;
            childClass.prototype=new B();
            childClass.prototype.constructor=childClass;
        }

        

        var Star=function(el,options){
            this.$el=$(el);
            this.$item=this.$el.find("li");
            this.opts=options;
            this.add=1;
            this.selectEvent="mouseover";
        }

        Star.prototype.init=function(){
           this.comStar(this.opts.num);
           if(!this.opts.readyOnly){
                 this.bindEvent();
           }
           
        };

        Star.prototype.comStar=function(num){
            num=parseInt(num);
            this.$item.each(function(ind){
                   if(ind

在优化过程中我主要用到了以下几方面思想:

  • 继承:因为代码的复用性太多,我针对有复用性的几个地方开辟了一个新的父类,让子类拥有和父类一样的属性和方法。
  • 面向对象的设计模式,虽然现在很多人都在喊函数式编程,但在这个插件的使用过程中并没有过多的用到这种思想
  • 在具体的编程过程中有些地方我已经进行了注释,如果还有不懂得可以私聊的方式进行

难点:

  • 在编程过程中,我认为可能的难点就是在半颗星的编程,在半颗星的编程过程中大家可以多停留一会。
  • 代码的完善需要更多的人参与其中,我希望有更多优秀的编程者可以参与其中一起讨论可以继续优化的地方以方便之后的改善。

结尾:

  • 在编程的过程中,我慢慢的发现了代码带来的魅力,无穷的想象力总能靠代码来实现。每次在看别人的Demo中的按例的时候总会看到别人的代码写的如此优雅,总让我羡慕不已,同时在社区的发展过程中,我每写一篇文章也会或多或少的结交更多的朋友,希望大家通过此篇文章也可以结交更多的编程好友,这或许是我每次能够继续写下去文章的动力吧。

时间:18年9.20日

你可能感兴趣的:(node.js,html5,html,css,javascript)