2
我想要一個滑塊,用於視頻持續時間,範圍從00:00:10到01:30:00。 我得到的持續時間以毫秒爲單位,我也需要以毫秒爲單位發送它們。 我打電話noUiSlider.create
我2個格式化功能和update
事件處理程序:NoUiSlider - 格式化毫秒到hh:mm:ss發送undefined
var timeSlider = document.getElementById('timelineranger');
noUiSlider.create(timeSlider, {
start: [10000, 5400000],
connect: true,
behaviour: 'tap-drag',
step: 10000,
range: {
'min': 10000,
'max': 5400000
},
format: {
to: HHMMSSToms,
from: msToHHMMSS
}
});
function msToHHMMSS(value) {
var duration = moment.duration(parseInt(value, 10));
var addZero = function(v) { return (v<10 ? '0' : '') + Math.floor(v); };
var time = addZero(duration.hours()) +
':' + addZero(duration.minutes()) +
':' + addZero(duration.seconds());
return time;
}
function HHMMSSToms(value) {
var a = value.toString().split(':');
var ms = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]) * 1000;
return ms;
}
timeSlider.noUiSlider.on('update', function (values, handle) {
if (handle) {
$('.timeMax').text(values[handle]);
} else {
$('timeMin').text(values[handle]);
}
});
的問題是,msToHHMMSS
函數被調用3倍,10000
,5400000
然後值再次用10000
,然後HHMMSSToms
被調用,但值爲undefined
並引發錯誤:Cannot read property 'split' of undefined
。
我看過this question,但正如我剛纔所說,我需要hh:mm:ss
格式。
刪除'format'選項並在'update'事件中調用'msToHHMMSS'函數是一個非常好的主意!有用!非常感謝大家:) – FireBrand
我可以得到這個完整的代碼嗎? –