jQuery 星级插件
CSS:
.rating_ui { position: relative; display: inline-block; overflow: hidden; width: 100%; height: 12px; margin-bottom: 10px; background-color: whitesmoke; // border-radius: 3px !important; -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3); z-index: 2; } .rating_ui > .rating { position: absolute; height: 100%; line-height: 12px; color: white; text-align: center; border-right: #cecece solid 2px; } .rating_ui.editable > .rating { cursor: pointer; } .rating_ui > .rating.rating_active { background-color: #ffcc00; -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); -webkit-transition: width 0.6s ease; -o-transition: width 0.6s ease; transition: width 0.6s ease; } .rating_ui.editable > .rating:hover { background-color: #ffcc00; border-right: #d9534f solid 2px; -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); -webkit-transition: width 0.6s ease; -o-transition: width 0.6s ease; transition: width 0.6s ease; } .rating_ui > .rating-1 { width: 20%; z-index: 50; } .rating_ui > .rating-2 { width: 40%; z-index: 40; } .rating_ui > .rating-3 { width: 60%; z-index: 30; } .rating_ui > .rating-4 { width: 80%; z-index: 20; } .rating_ui > .rating-5 { width: 100%; z-index: 10; } <div class="rating_ui editable"> <div class="rating rating-1 rating_active" title="1" data-rating="1"></div> <div class="rating rating-2" title="2" data-rating="2"></div> <div class="rating rating-3" title="3" data-rating="3"></div> <div class="rating rating-4" title="4" data-rating="4"></div> <div class="rating rating-5" title="5" data-rating="5"></div> <input type="hidden" class="level" name="level" value="2"> </div>
js插件:
(function ($, window) { $.fn.ratingStar = function (options) { function get_value($rating) { return window.parseInt($('.rating.rating_active', $rating).data('rating')); } function set_value(level, $rating) { $('input.level', $rating).val(level); $('.rating', $rating).removeClass('rating_active'); $('.rating-' + level, $rating).addClass('rating_active'); } function init_value($rating) { var level = window.parseInt($('input.level', $rating).val()); set_value(level, $rating); } return this.each(function () { var $rating = $(this); init_value($rating); $rating.on('click', function (event) { if ($(this).hasClass('editable')) { var $active_rating = $(event.target); var level = window.parseInt($active_rating.data('rating')); set_value(level, $(this)); return false; } }); }) } })(jQuery, window);
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17