此处为 JS、iframe 和Vimeo api 的新手据我所知, document.querySelector('iframe') 只会选择第一个 iframe。但是,如果我有一个视频页面,我希望它适用于多个特定视频。在相关的 iframe 中,我添加了 class='noskip'然后迭代我认为我可以做:var noskips = document.querySelectorAll('.noskip');for (var i = 0, len = noskips.length; i < len; i++) { }但我不确定如何将每个 iframe 传递到实际的播放器函数中:var player = new Vimeo.Player(iframe);var timeWatched = 0;player.on("timeupdate", function(data) { if (data.seconds - 1 < timeWatched && data.seconds > timeWatched) { timeWatched = data.seconds; }});player.on("seeked", function(data) { if (timeWatched < data.seconds) { player.setCurrentTime(timeWatched); }});
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
好的,我想我解决了。欢迎提出改进建议!
var noskips = document.querySelectorAll('.noskip');
var iframes = Array.prototype.slice.call(noskips);
iframes.forEach(function(iframe) {
var player = new Vimeo.Player(iframe);
var timeWatched = 0;
player.on("timeupdate", function(data) {
if (data.seconds - 1 < timeWatched && data.seconds > timeWatched) {
timeWatched = data.seconds;
}
});
player.on("seeked", function(data) {
if (timeWatched < data.seconds) {
player.setCurrentTime(timeWatched);
}
});
});
添加回答
举报
0/150
提交
取消