如何为离子范围滑块设置当前时间?

问题描述 投票:0回答:1

我在jQuery中非常笨。我有一个具有以下设置的离子范围滑块:

$("#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分钟。

jquery plugins jquery-plugins
1个回答
2
投票

创建对象后或在创建时,您可以计算所需的精确值:

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
});
© www.soinside.com 2019 - 2024. All rights reserved.