$.fn.findrating(stars = 5) (jQuery)
HejJeg har lavet en funktion til at lave rating via jQuery...
Mit problem er, at jeg ikke kan få lov til at angive hvor mange stjerner der skal være som udgangspunkt, så man ikke skal angive hvor mange stjerner der skal være - med mindre man ønsker et andet antal end 5...
min funktion
// Find rating
$.fn.findrating = function(stars = 5) /* <--- Dette melder fejl */ {
var t = $(this);
$.each(t, function() {
var th = $(this);
if (stars <= 0) {
stars = 5;
}
for (var i = 1; i <= stars; i++) {
th.append('<div class="stars"></div>');
}
var ch = th.children();
var chH = th.children().height();
var chW = th.children().width();
var newRating = th.attr('rating');
th.prepend('<div class="rating"></div>');
var rating = th.find('.rating');
if (stars < newRating) {
newRating = stars;
}
th.append('<div style="clear: both;"></div>');
ch.css({'position': 'relative', 'z-index': 2000});
rating.css({'position': 'absolute', 'z-index': 1000, 'width': chW * newRating + 'px', 'height': chH + 'px ', top: 'ch'});
});
};
$('.star').findrating(5);