问题
我需要在调用 timeupdate 后检索 clientX
(水平鼠标位置)值。但是,timeupdate 事件不会返回 clientX
,而且我似乎找不到解决此问题的方法。
到目前为止的代码(示例)
var point = {
to: function(e){
console.log(e.clientX); // returns undefined
}
}
audio.addEventListener("timeupdate", function(e){
point.to(e);
});
有什么办法可以实现我想要的吗?到目前为止,Google 和 StackOverflow 都没有返回有希望的结果。
干杯。
最佳答案
您无法访问该事件的 clientX
或 clientY
。您需要做的是捕获鼠标位置并将其存储在另一个事件中。在此示例中,我使用 mousemove
来捕获和存储鼠标位置。
let mouseX;
let mouseY;
var point = {
to: function(e){
console.log(mouseX, mouseY);
}
}
audio.addEventListener("mousemove", e => {
mouseX = e.clientX;
mouseY = e.clientY;
});
audio.addEventListener("timeupdate", function(e){
point.to(e);
});
<audio id="audio" controls src="http://soundbible.com/mp3/harley-davidson-daniel_simon.mp3"/>
关于javascript - 如何在音频时间更新上获取 clientx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50902680/