[英]Cannot read property 'toFixed' of undefined. Uncaught TypeError
I'm trying to understand why my code block doesn't work.我试图理解为什么我的代码块不起作用。 I am using JQuery as well as vanilla JS.我正在使用 JQuery 以及 vanilla JS。
Here's my code.这是我的代码。
// 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);
Any help is much appreciated.任何帮助深表感谢。
Thanks!谢谢!
I actually fixed it.我实际上修复了它。
In my case, the problem didn't have anything to do with toFixed()
.就我而言,问题与toFixed()
无关。
My problem was due to mixing JQuery and Vanilla Javascript.我的问题是由于混合了 JQuery 和 Vanilla Javascript。
Like this,像这样,
let video = $(".video");
video.on("timeupdate", function() {
let colorPos = video.currentTime / video.duration;
color.style.width = colorPos * 100 + "%";
if (video.ended) {
btn.className = "replay";
}
});
Solution解决方案
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";
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.