我试图理解为什么我的代码块不起作用。我正在使用 JQuery 以及 vanilla JS。
这是我的代码。
// update every 1 second on time.
setInterval(function() {
// get current time and duration of entire video
let getTimePaused = video.currentTime;
let vidTime = getTimePaused.toFixed(0);
let formatTime = minTommss(vidTime);
$(".timeLeft").text(
minTommss(vidTime / 60) + " - " + minTommss((video.duration / 60) + 0.01)
);
}, 1000);
非常感谢任何帮助。
谢谢!
最佳答案
我确实修复了它。
就我而言,问题与 toFixed()
没有任何关系。
我的问题是由于混合 JQuery 和 Vanilla Javascript 造成的。
像这样,
let video = $(".video");
video.on("timeupdate", function() {
let colorPos = video.currentTime / video.duration;
color.style.width = colorPos * 100 + "%";
if (video.ended) {
btn.className = "replay";
}
});
解决方案
let video = document.querySelector(".video");
video.addEventListener("timeupdate", function() {
let colorPos = video.currentTime / video.duration;
color.style.width = colorPos * 100 + "%";
if (video.ended) {
btn.className = "replay";
}
});
关于javascript - 无法读取未定义的属性 'toFixed'。未捕获的类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55387791/