gpt4 book ai didi

jquery - Flexslider 2 和 YouTube API

转载 作者:行者123 更新时间:2023-12-03 06:28:30 25 4
gpt4 key购买 nike

我正在使用 Flexslider2 并在最后一张幻灯片中添加了一个 YouTubevideo 并插入了 YouTube API。如果我播放视频但然后单击转到另一个 slider ,则视频继续在后台播放 - 当我转到另一个 slider 时如何让视频停止?

另外,如何让视频填充框架?我已将其设置为 100%,但目前它只填满了三分之一的区域。

这是我的代码 - 任何帮助都会很棒!

<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta content="charset=utf-8">
<title>FlexSlider 2</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">

<!-- Demo CSS -->
<link rel="stylesheet" href="http://www.swimmingcover.co.uk/slider/css/demo.css" type="text/css" media="screen" />
<link rel="stylesheet" href="http://www.swimmingcover.co.uk/slider/css/flexslider.css" type="text/css" media="screen" />

<!-- Modernizr -->
<script src="http://www.swimmingcover.co.uk/slider/js/modernizr.js"></script>

</head>
<body class="loading">

<div id="main" style="width:30%; padding-top:40px;" role="main" >
<div id="slider" class="flexslider">
<ul class="slides">
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_cheesecake_brownie.jpg" /></li>
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_lemon.jpg" /></li>
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_caramel.jpg" /></li>
<li><iframe id="player" height="100%" src="http://www.youtube.com/embed/gDsj5UZ_1bA?rel=0" frameborder="0" allowfullscreen></iframe></li>
</ul>
</div>
<div id="carousel" class="flexslider">
<ul class="slides">
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_cheesecake_brownie.jpg" /></li>
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_lemon.jpg" /></li>
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_adventurer_caramel.jpg" /></li>
<li><img src="http://www.swimmingcover.co.uk/slider/images/kitchen_video.jpg" /></li>
</ul>
</div>

</div>

<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.min.js">\x3C/script>')</script>

<!-- FlexSlider -->
<script defer src="http://www.swimmingcover.co.uk/slider/js/jquery.flexslider.js"></script>

<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}

// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}

</script>

<script type="text/javascript">
$(function(){
SyntaxHighlighter.all();
});
$(window).load(function(){
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
itemWidth: 90,
itemMargin: 5,
asNavFor: '#slider'
});

$('#slider').flexslider({
animation: "slide",
video: true,
controlNav: false,
animationLoop: false,
slideshow: false,
sync: "#carousel",
start: function(slider){
$('body').removeClass('loading');
}
});
});
</script>


<!-- Syntax Highlighter -->
<script type="text/javascript" src="http://www.swimmingcover.co.uk/slider/js/shCore.js"></script>
<script type="text/javascript" src="http://www.swimmingcover.co.uk/slider/js/shBrushXml.js"></script>
<script type="text/javascript" src="http://www.swimmingcover.co.uk/slider/js/shBrushJScript.js"></script>

<!-- Optional FlexSlider Additions -->
<script src="http://www.swimmingcover.co.uk/slider/js/jquery.easing.js"></script>
<script src="http://www.swimmingcover.co.uk/slider/js/jquery.mousewheel.js"></script>
<script defer src="http://www.swimmingcover.co.uk/slider/js/demo.js"></script>

</body>
</html>

最佳答案

这个问题的第一个问题是这个类被设置为“slider”而不是“slides”。

改变

    <li><iframe id="player" height="100%" src="http://www.youtube.com/embed/gDsj5UZ_1bA?rel=0" frameborder="0" allowfullscreen></iframe></li>


   <iframe class="youtube" width="420" height="315" src="https://www.youtube.com/embed/gDsj5UZ_1bA" frameborder="0" allowfullscreen></iframe>

这应该给出所需的尺寸。

有关如何停止播放器的信息,请参见此示例
https://gist.github.com/weissmike/6390241

并在选择器隐藏时调用它。
http://api.jquery.com/hidden-selector/

关于jquery - Flexslider 2 和 YouTube API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23093733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com