JavaScript
- 2 ответа
- 0 вопросов
2
Вклад в тег
function move(e, obj) {
var summ = 0;
var id = obj.next().attr('id').substr(1);
var progress = e.pageX - obj.offset().left;
var width = obj.width(),
leftEdge = obj.offset().left,
rightEdge = obj.offset().left + width;
if (e.pageX < leftEdge) {
progress = 0;
} else if (e.pageX >= rightEdge) {
progress = obj.width();
}
var rating = progress * 5 / width;
$('#param' + id).text(rating.toFixed(2));
obj.next().width(progress);
$('.stars__count').each(function() {
summ += parseFloat($(this).text());
});
};
$('.stars__data').on('mouseleave', function(e) {
var summ = 0;
var id = $(this).next().attr('id').substr(1);
var width = $(this).width(),
reasonableWidth = width * 0.1,
height = $(this).height(),
leftEdge = $(this).offset().left,
topEdge = $(this).offset().top,
bottomEdge = topEdge + height,
exitPointX = e.pageX,
exitPointY = e.pageY;
if ( ( exitPointY >= topEdge ) && ( exitPointY <= bottomEdge ) && ( exitPointX > (leftEdge + reasonableWidth) ) ) {
$('#param' + id).text("5");
$(this).next().width(width);
$('.stars__count').each(function() {
summ += parseFloat($(this).text());
});
}
});