如何计算滑块宽度的总数量百分比

How to compute total number percentage for slider width?

本文关键字:百分比 何计算 计算      更新时间:2023-09-26

我正在尝试修改滑块: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();
}

使用 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 + '%'});
    };