我正在尝试修改滑块:plunker,以更新进度条百分比,如总数值,以便在滑动期间在步骤之间跳转。如何计算圆形百分比作为滑块中的值?
负责此事的职能:
function mousemove(event) {
scope.percent = Math.max(0, Math.min((event.clientX - scope.l) / scope.w * 100, 100));
if(scope.updateOnDrag)
{
scope.update();
}
scope.redraw();
}
答案 0 :(得分:1)
使用Math.round()
计算left
/ distance
值
scope.redraw = function() {
var percentMultiplier = scope.percent / 100;
var steppedPercent = (Math.round(percentMultiplier * scope.range) / scope.range) * 100;
scope.btn.css({'display': ngModel.$isEmpty(ngModel.$viewValue) ? 'none' : 'block'});
scope.btn.css({'left': steppedPercent + '%'});
scope.bar.css({'width': steppedPercent + '%'});
};