如何将当前时间设置为 Ion Range Slider?

How to set current time to Ion Range Slider?

我在 jQuery 时很笨。我有一个具有以下设置的 Ion Range Slider:

$("#range_time").ionRangeSlider({
        type: "double",
        values: [
            "08:00", "08:15", "08:30", "08:45", 
            "09:00", "09:15", "09:30", "09:45", 
            "10:00", "10:15", "10:30", "10:45", 
            "11:00", "11:15", "11:30", "11:45", 
            "12:00", "12:15", "12:30", "12:45", 
            "13:00", "13:15", "13:30", "13:45", 
            "14:00", "14:15", "14:30", "14:45", 
            "15:00", "15:15", "15:30", "15:45", 
            "16:00", "16:15", "16:30", "16:45", 
            "17:00", "17:15", "17:30", "17:45", 
            "18:00", "18:15", "18:30", "18:45", 
            "19:00"
        ],
        from_min: 0,
        to: 8,
        drag_interval: true,
        min_interval: 8,

    });

如何将 from_min 设置为最近的当前时间(如果它在 8:00-17:00 范围内)而不是 from: 0?步长为 15 分钟。

创建对象后或在创建时您可以计算出您要查找的正确值:

var timeToRound = new Date();
var hh = timeToRound.getHours();
var mm = Math.round(timeToRound.getMinutes() / 15) * 15;
var froMin = 0;
if (hh >= 8 && hh < 19 || (hh == 19 && mm == 0)) {
  froMin = (hh - 8) * 4 + (mm / 15);
}
var slider = $("#range_time").data("ionRangeSlider"); // changed the identifier to match the initial post example
slider.update({
  from_min: froMin
});