【发布时间】:2018-12-28 20:42:49
【问题描述】:
我想为每个具有相同类名的视频使用此流体播放器功能。我听说我可以使用Array.forEach() 方法做到这一点,但我不知道怎么做。
我也尝试过使用普通的 for 循环,并在每个数组元素上执行 Fluid Player 函数,但它不起作用。
我做错了什么?
<!DOCTYPE html>
<html>
<body>
<link rel="stylesheet" href="https://cdn.fluidplayer.com/v2/current/fluidplayer.min.css" type="text/css"/>
<script src="https://cdn.fluidplayer.com/v2/current/fluidplayer.min.js"></script>
<video class = "classname" id="short" height="225" loop controls>
<source src="deja vu.mp4" type="video/mp4"/>
</video>
<video class = "classname" id="short" height="225" loop controls>
<source src="deja vu.mp4" type="video/mp4"/>
</video>
<video class = "classname" id="short" height="225" loop controls>
<source src="deja vu.mp4" type="video/mp4"/>
</video>
</body>
<script type="text/javascript">
var array = document.getElementByClassName('classname');
Array.forEach();
</script>
<script type="text/javascript">
var myFP = fluidPlayer(
'short',
{
layoutControls: {
fillToContainer: false,
primaryColor: false,
posterImage: false,
autoPlay: false,
playButtonShowing: true,
playPauseAnimation: true,
mute: false,
logo: {
imageUrl: null,
position: 'top left',
clickUrl: null,
opacity: 1,
mouseOverImageUrl: null,
imageMargin: '2px',
hideWithControls: false,
showOverAds: false
},
htmlOnPauseBlock: {
html: null,
height: null,
width: null
},
allowDownload: false,
allowTheatre: false,
playbackRateEnabled: false,
controlBar: {
autoHide: true,
autoHideTimeout: 1,
animated: false
},
},
vastOptions: {
}
}
);
</script>
</html>
【问题讨论】:
-
Ehh ...你能告诉我们你想在迭代中做什么吗?此外,
getElementByClassName不返回数组,它返回一个 HTMLCollection 对象。尽管该对象在现代浏览器中具有forEach方法。 -
在我使用 getElementByClassName 函数制作的数组上
-
有点不清楚你在问什么,也许forEach 的文档有帮助..?
-
那么是否可以按照我现在使用的方式进行操作?
-
您当前的
fluidPlayer(调用似乎没有接受任何与元素相关的参数,但...
标签: javascript html arrays for-loop