星星評分插件starScore.js

1.引入插件
記得先引入jquery,在引入starScore.js.這個插件不需要引入css文件,直接寫在html中,修改樣式直接修改就OK。

<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script src="js/starScore.js"></script>

2.css

<style>
        body,li,p,ul {
    margin: 0;
    padding: 0;
    font: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
}
ul, li, ol { list-style: none; }

/* 重置文本格式元素 */
a {
    text-decoration: none;
    cursor: pointer;
    color:#333333;
    font-size:14px;
}
a:hover {
    text-decoration: none;
}
.clearfix::after{
    display:block;
    content:'';
    height:0;
    overflow:hidden;
    clear:both;
}

/*星星樣式*/
.content{
    width:600px;
    margin:0 auto;
    padding-top:20px;
}
.title{
    font-size:14px;
    background:#dfdfdf;
    padding:10px;
    margin-bottom:10px;
}
.block{
    display: inline-block;
    width:160px;
    margin:10px 0;

    line-height:21px;
}
.block .star_score{
    float:left;
}
.star_list{
    height:21px;
    margin:50px;
    line-height:21px;
}
.block p,.block .attitude{
    padding-left:20px;
    line-height:21px;
    display:inline-block;
}
.block p span{
    color:#C00;
    font-size:16px;
    font-family:Georgia, "Times New Roman", Times, serif;
}

.star_score {
    background:url(../img/star_link.png);
    width:160px;
    height:21px;
    position:relative;
}

.star_score a{
    height:21px;
    display:block;
    text-indent:-999em;
    position:absolute;
    left:0;
}

.star_score a:hover{
    background:url(../img/star_hover.png);
    left:0;
}

.star_score a.clibg{
    background:url(../img/star_hover.png);
    left:0;
}

#starttwo .star_score {
    background:url(../img/star_link.png);
}

#starttwo .star_score a:hover{
    background:url(../img/star_hover.png);
    left:0;
}

#starttwo .star_score a.clibg{
    background:url(../img/star_hover.png);
    left:0;
}

/*星星樣式*/

.show_number{
    float: left;
    margin-top: 17px;
}

.show_number li{
    width:60px;
    border:0;
}

.atar_Show{
    background:url(../img/star_link.png);
    background-size: 12px 12px;
    width:60px;
    height:12px;
    position:relative;
    /*top: 16px;*/
    float:left;
}

.atar_Show p{
    background:url(../img/star_hover.png);
    background-size: 12px 12px;
    left:0;
    height:12px;
    width:60px;
}

.show_number li span{
    display:inline-block;
    line-height:21px;
}

</style>

3.html

<div class="content">
    <p class="title">半顆星評分</p>
    <div id="startone" class="block clearfix">
        <div class="star_score"></div>
        <p style="float:left;">您的評分:<span class="fenshu"></span> 分</p>
        <div class="attitude"></div>
    </div>
    <p class="title">1顆星評分</p>
    <div id="starttwo" class="block clearfix">
        <div class="star_score"></div>
        <p style="float:left;">您的評分:<span class="fenshu"></span> 分</p>
        <div class="attitude"></div>
    </div>
    <p class="title">分數(shù)展示</p>
    <ul class="show_number clearfix">
        <li>
            <div class="atar_Show">
                <p tip="2.5"></p>
            </div>
        </li>
    </ul>
    <ul class="show_number clearfix">
        <li>
            <div class="atar_Show">
                <p tip="4.5"></p>
            </div>
        </li>

    </ul>
    <ul class="show_number clearfix">
        <li>
            <div class="atar_Show">
                <p tip="5"></p>
            </div>
        </li>
    </ul>
</div>

4.js

<script>
    //星星展示分數(shù)
    $(".show_number li p").each(function(index, element) {
        var num=$(this).attr("tip");
        var www=num*12;//
        $(this).css("width",www);
        $(this).parent(".atar_Show").siblings("span").text(num+"分");
    });
    //星星 ---  評論星星,可點擊評論
    scoreFun($("#starttwo"),{
        fen_d:22,//每一個a的寬度
        ScoreGrade:5//a的個數(shù) 10或者
    });
</script>

如果出現(xiàn)重影的情況,請把星星的寬度改一下,星星的父元素寫成5顆星星加起來的寬度,

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標準。 注意:講述HT...
    kismetajun閱讀 28,809評論 1 45
  • 1 Webpack 1.1 概念簡介 1.1.1 WebPack是什么 1、一個打包工具 2、一個模塊加載工具 3...
    Kevin_Junbaozi閱讀 7,022評論 0 16
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標簽默認的外補...
    _Yfling閱讀 14,143評論 1 92
  • 這個名字是聊天時偶然給你取的,算是一廂情愿的惡趣味,我也想不出別的比這可愛的名字了,雖然一開始你是拒絕的,但...
    云煙故雨閱讀 670評論 0 0
  • 安裝 Git Bash 安裝教程 初步使用 一般使用 Git 有兩種方式:第一種:自己新建一個項目,然后克隆下來在...
    _空空閱讀 363評論 0 0

友情鏈接更多精彩內(nèi)容