咨詢電(diàn)話(huà):023-88959644    24小(xiǎo)時(shí)服務熱線:400-023-8809
NEWS CENTER ·
新聞動态
關注中技(jì)互聯 關注前沿

評星簡版怎麽編寫!javascript淘寶評星簡版實例!

發表日期:2010-09-19    文章編輯:王東    浏覽次數(shù):15    标簽:

【程序源碼】這個(gè)效果主要體(tǐ)現在CSS和(hé)javascript的配合上(shàng)CSS代碼ul, li {margin: 0; padding: 0; border: 0;}.shop-rating {

  【程序源碼】

  這個(gè)效果主要體(tǐ)現在CSS和(hé)javascript的配合上(shàng)

  CSS代碼

ul, li {margin: 0; padding: 0; border: 0;}
.shop-rating {
    height: 25px;
    overflow: hidden;
    zoom: 1;
    padding: 2px 0;
    position: relative;
    z-index: 999;
    font:12px Arial;
    color:#000;
    line-height:1.2em
}
.shop-rating span {
    height: 23px;
    display: block;
    line-height: 23px;
    float: left;
}
.shop-rating span.title {
    width: 125px;
    text-align: right;
    margin-right: 5px;
}
.shop-rating ul {
    float: left;
}
.shop-rating .result {
    margin-left: 20px;
    padding-top: 2px;
}
.shop-rating .result span {
    color: #ff6d02;
}
.rating-level,
.rating-level a {
     background: url(http://images.cnblogs.com/cnblogs_com/bluedream2009/201609/o_star.png) no-repeat scroll 1000px 1000px;
}
.rating-level {
    background-position: 0px 0px;
    width: 120px;
    height: 23px;
    position: relative;
    z-index: 1000;
}
.shop-rating .result em {
    color: #f60;
    font-family: arial;
    font-weight: bold;
}
.rating-level li {
    display: inline;
}
.rating-level a {
    line-height: 23px;
    height: 23px;
    position: absolute;
    top: 0px;
    left: 0px;
    text-indent: -999em;
    *zoom: 1;
    outline: none;
}
.rating-level a.one-star {
    width: 20%;
    z-index: 6;
}
.rating-level a.two-stars {
    width: 40%;
    z-index: 5;
}
.rating-level a.three-stars {
    width: 60%;
    z-index: 4;
}
.rating-level a.four-stars {
    width: 80%;
    z-index: 3;
}
.rating-level a.five-stars {
    width: 100%;
    z-index: 2;
}
.rating-level .current-rating, .rating-level a:hover {background-position:0 -28px}
.rating-level a.one-star:hover,.rating-level a.two-stars:hover,.rating-level a.one-star.current-rating,.rating-level a.two-stars.current-rating{background-position:0 -116px;}
.rating-level .three-stars .current-rating,.rating-level .four-stars .current-rating,.rating-level .five-stars .current-rating{background-position:0 -28px;}

HTML結構

<div class="shop-rating">
    <span class="title">你(nǐ)對我人(rén)品的評價:</span>
    <ul class="rating-level" id="stars2">
        <li><a href="javascript:void(0);" class="one-star" star:value="20">20</a></li>
        <li><a href="javascript:void(0);" class="two-stars" star:value="40">40</a></li>
        <li><a href="javascript:void(0);" class="three-stars" star:value="60">60</a></li>
        <li><a href="javascript:void(0);" class="four-stars" star:value="80">80</a></li>
        <li><a href="javascript:void(0);" class="five-stars" star:value="100">100</a></li>
    </ul>
    <span id="stars2-tips" class="result"></span>
    <input type="hidden" id="stars2-input" name="b" value="" size="2" />
</div>

  Javascript代碼

var TB = function() {
    var T{$selection}nbsp;= function(id) { return document.getElementById(id) }
    var T$ = function(r, t) { return (r || document).getElementsByTagName(t) }
    var Stars = function(cid, rid, hid, config) {
            var lis = T$(T$(cid), 'li'), curA;
            for (var i = 0, len = lis.length; i < len; i++) {
                lis[i]._val = i;
                lis[i].onclick = function() {
                    T$(rid).innerHTML = '<em>' + (T$(hid).value = T$(this, 'a')[0].getAttribute('star:value')) + '分</em> - ' + config.info[this._val];
                    curA = T$(T$(cid), 'a')[T$(hid).value / config.step - 1];
                };
                lis[i].onmouseout = function() {
                    curA && (curA.className += config.curcss);
                }
                lis[i].onmouseover = function() {
                    curA && (curA.className = curA.className.replace(config.curcss, ''));
                }
            } 
    };
    return {Stars: Stars}
}().Stars('stars2', 'stars2-tips', 'stars2-input', {
            'info' : ['人(rén)品極差', '人(rén)品不咋地', '人(rén)品一般吧(ba)', '人(rén)品不錯', '人(rén)品極好啊'],
            'curcss': ' current-rating',
            'step': 20
        });


重慶中技互聯網信息咨詢有限公司
重慶網站(zhàn)建設事業部官方網:www.zjcoo.com
電(diàn)子商務建站(zhàn)事業部咨詢電(diàn)話(huà):023-67742189
門(mén)戶網站(zhàn)品牌加盟推廣電(diàn)話(huà):023-67742189
7*24小(xiǎo)時(shí)服務電(diàn)話(huà):023-67742189
媒體(tǐ)合作(zuò)電(diàn)話(huà):13883323406
投資合作(zuò)電(diàn)話(huà):13896068183
QQ及郵件地址:446515345@qq.com

如沒特殊注明(míng),文章均為(wèi)中技(jì)互聯原創,轉載請(qǐng)注明(míng)來(lái)自www.zjcoo.com
相關新聞

CopyrightZJCOO technology Co., LTD. All Rights Reserved.    

渝ICP 備11003429号

  • qq客服
  • 公衆号
  • 手機版
  • 新浪微博