$(‘#rating-star‘).on(‘click‘, ‘a‘, function () {
$(‘#goodLevel‘).val(this.innerHTML);
}).on(‘mouseenter‘, ‘a‘, function () {
setStar(this);
}).on(‘mouseleave‘, ‘a‘, function () {
var level = $(‘#goodLevel‘).val();
var $stars = $(‘#rating-star > a‘);
if (level == ‘‘) {
$stars.css(‘background-position‘, ‘0 -90px‘);
} else {
setStar($stars[level]);
}
});
function setStar(star) {
var $this = $(star);
var level = $this.
html();
var n;
if (level == ‘2‘) {
n = ‘0 -30px‘;
} else if (level == ‘1‘) {
n = ‘0 0‘;
} else {
n = ‘0 -60px‘;
}
$this.prevAll().andSelf().css(‘background-position‘, n);
$this.nextAll().css(‘background-position‘, ‘0 -90px‘);
}