我在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分钟。
答案 0 :(得分:2)
创建对象后或在创建时,您可以计算您要查找的rigth值:
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").data("ionRangeSlider");
slider.update({
from_min: froMin
});