Vimeo api - 遍历页面上的多个视频

此处为 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);

  }

});


阿波罗的战车
浏览 133回答 1
1回答

精慕HU

好的,我想我解决了。欢迎提出改进建议!var noskips = document.querySelectorAll('.noskip');var iframes = Array.prototype.slice.call(noskips);iframes.forEach(function(iframe) {&nbsp; &nbsp; var player = new Vimeo.Player(iframe);&nbsp; &nbsp; var timeWatched = 0;&nbsp; &nbsp; player.on("timeupdate", function(data) {&nbsp; &nbsp; &nbsp; if (data.seconds - 1 < timeWatched && data.seconds > timeWatched) {&nbsp; &nbsp; &nbsp; &nbsp; timeWatched = data.seconds;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; player.on("seeked", function(data) {&nbsp; &nbsp; &nbsp; if (timeWatched < data.seconds) {&nbsp; &nbsp; &nbsp; &nbsp; player.setCurrentTime(timeWatched);&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp;&nbsp;});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript