Javascript 在内容上方的窗口中播放Youtube iframe
我的页面上有几个小视频。如果有人点击一个视频,它应该在页面中央播放一个更大尺寸的视频。 我不知道该搜索什么或如何搜索 有人能给我一个建议吗Javascript 在内容上方的窗口中播放Youtube iframe,javascript,iframe,youtube,Javascript,Iframe,Youtube,我的页面上有几个小视频。如果有人点击一个视频,它应该在页面中央播放一个更大尺寸的视频。 我不知道该搜索什么或如何搜索 有人能给我一个建议吗 谢谢大家! 我会使用模式。使它非常容易实现(如果您以前从未使用过它) 下面是一个如何使用它的示例(只需添加您自己的CSS样式),下面是文档: Youtube视频 情态标题 &时代; 我会使用模式。使它非常容易实现(如果您以前从未使用过它) 下面是一个如何使用它的示例(只需添加您自己的CSS样式),下面是文档: Youtube视频 情态标题 &时代
谢谢大家! 我会使用
模式
。使它非常容易实现(如果您以前从未使用过它)
下面是一个如何使用它的示例(只需添加您自己的CSS
样式),下面是文档:
Youtube视频
情态标题
&时代;
我会使用模式
。使它非常容易实现(如果您以前从未使用过它)
下面是一个如何使用它的示例(只需添加您自己的CSS
样式),下面是文档:
Youtube视频
情态标题
&时代;
当有人单击缩略图时,您可以使用Youtube API动态加载视频
<html>
<head>
<style>
.container {
display: flex;
flex-direction: column;
}
img {
width: 250px;
height: 250px;
}
</style>
</head>
<body>
<div class="container"><span>Thumbnail (click me)</span>
<div id="thumbs">
<img class="videoThumb" src="http://i3.ytimg.com/vi/WL96WqA6e9Y/maxresdefault.jpg" data-video="WL96WqA6e9Y">
<img class="videoThumb" src="http://i3.ytimg.com/vi/ZQy89tZ-mRU/hqdefault.jpg" data-video="ZQy89tZ-mRU">
</div>
</div>
<div class="container">
<span>Video</span>
<div id="videoContainer"></div>
</div>
<script>
// Load the Youtube IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function enlarge(event) {
//Get the video ID from the thumbnail
var videoID = event.target.attributes["data-video"].value;
//Get the video container
var container = document.getElementById("videoContainer");
//Clear it as youtube overwrites the element
container.innerHTML = "";
//Create element which will be replaced with video
var videoFrame = document.createElement('div');
//append to the container
container.appendChild(videoFrame);
//create youtube video
videoFrame.id = 'videoFrame';
new YT.Player('videoFrame', {
height: '360',
width: '640',
videoId: videoID
});
}
//Get all thumbnails
var vids = document.getElementsByClassName("videoThumb");
//Add event listener to all thumbnails
for(var i = 0; i < vids.length; i++) {
vids[i].addEventListener("click",enlarge);
}
</script>
</html>
.集装箱{
显示器:flex;
弯曲方向:立柱;
}
img{
宽度:250px;
高度:250px;
}
缩略图(单击我)
视频
//异步加载Youtube IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/player_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
功能放大(事件){
//从缩略图中获取视频ID
var videoID=event.target.attributes[“数据视频”].value;
//获取视频容器
var container=document.getElementById(“videoContainer”);
//在youtube覆盖元素时清除它
container.innerHTML=“”;
//创建将被视频替换的元素
var videoFrame=document.createElement('div');
//附加到容器中
容器。附加子对象(视频帧);
//创建youtube视频
videoFrame.id='videoFrame';
新YT.播放器(“视频帧”{
高度:'360',
宽度:“640”,
videoId:videoId
});
}
//获取所有缩略图
var vids=document.getElementsByClassName(“videoThumb”);
//将事件侦听器添加到所有缩略图
对于(变量i=0;i
当有人单击缩略图时,您可以使用Youtube API动态加载视频
<html>
<head>
<style>
.container {
display: flex;
flex-direction: column;
}
img {
width: 250px;
height: 250px;
}
</style>
</head>
<body>
<div class="container"><span>Thumbnail (click me)</span>
<div id="thumbs">
<img class="videoThumb" src="http://i3.ytimg.com/vi/WL96WqA6e9Y/maxresdefault.jpg" data-video="WL96WqA6e9Y">
<img class="videoThumb" src="http://i3.ytimg.com/vi/ZQy89tZ-mRU/hqdefault.jpg" data-video="ZQy89tZ-mRU">
</div>
</div>
<div class="container">
<span>Video</span>
<div id="videoContainer"></div>
</div>
<script>
// Load the Youtube IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function enlarge(event) {
//Get the video ID from the thumbnail
var videoID = event.target.attributes["data-video"].value;
//Get the video container
var container = document.getElementById("videoContainer");
//Clear it as youtube overwrites the element
container.innerHTML = "";
//Create element which will be replaced with video
var videoFrame = document.createElement('div');
//append to the container
container.appendChild(videoFrame);
//create youtube video
videoFrame.id = 'videoFrame';
new YT.Player('videoFrame', {
height: '360',
width: '640',
videoId: videoID
});
}
//Get all thumbnails
var vids = document.getElementsByClassName("videoThumb");
//Add event listener to all thumbnails
for(var i = 0; i < vids.length; i++) {
vids[i].addEventListener("click",enlarge);
}
</script>
</html>
.集装箱{
显示器:flex;
弯曲方向:立柱;
}
img{
宽度:250px;
高度:250px;
}
缩略图(单击我)
视频
//异步加载Youtube IFrame播放器API代码。
var tag=document.createElement('script');
tag.src=”https://www.youtube.com/player_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
功能放大(事件){
//从缩略图中获取视频ID
var videoID=event.target.attributes[“数据视频”].value;
//获取视频容器
var container=document.getElementById(“videoContainer”);
//在youtube覆盖元素时清除它
container.innerHTML=“”;
//创建将被视频替换的元素
var videoFrame=document.createElement('div');
//附加到容器中
容器。附加子对象(视频帧);
//创建youtube视频
videoFrame.id='videoFrame';
新YT.播放器(“视频帧”{
高度:'360',
宽度:“640”,
videoId:videoId
});
}
//获取所有缩略图
var vids=document.getElementsByClassName(“videoThumb”);
//将事件侦听器添加到所有缩略图
对于(变量i=0;i
A模式?我想这对你有用谢谢你的回答!这是正确的方向。但不幸的是我不能使用它们。我有一个iFrame(Vimeo或Youtube)作为一个小视频在页面上运行,并希望通过单击在内容上显示它。你知道这方面的解决方案吗?在这个页面上,我希望视频在点击内容后打开。模式?我想这对你有用谢谢你的回答!这是正确的方向。但不幸的是我不能使用它们。我有一个iFrame(Vimeo或Youtube)作为一个小视频在页面上运行,并希望通过单击在内容上显示它。你知道这方面的解决方案吗?在这个页面上,我希望视频可以在点击后打开。谢谢你的回答!这是正确的方向。但不幸的是我不能使用它们。我有一个iFrame(Vimeo或Youtube)作为一个小视频在页面上运行,并希望通过单击在内容上显示它。感谢您的回答!这是正确的方向。但不幸的是我不能使用它们。我有一个iFrame(Vimeo或Youtube)作为一个小视频在页面上运行,并希望通过单击在内容上显示它。