我正在将Youtube视频添加到carousal中,其中包含下一个和上一个按钮。我还添加了演示链接..
如何在下一个和上一个按钮上更改标题,描述,总视图?
<script type="text/javascript">
$(document).ready(function(){});
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/cZxy-GpHLCQ_Ss9sGJfWhzBAIOMDYxMN?v=2&alt=json&callback=?';
var videoURL= 'http://www.youtube.com/watch?v=';
$.getJSON(playListURL, function(data) {
var list_data="";
$.each(data.feed.entry, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var url = videoURL + videoID;
var thumb = "http://img.youtube.com/vi/"+ videoID +"/default.jpg";
list_data += '<div><a href= "#" title="'+ feedTitle +'"><img src="'+ thumb +'" width="213px" height="141px"/></a></div>';
});
$(list_data).appendTo(".slides");
$('.carousel').carousel({carouselWidth:930,carouselHeight:330,directionNav:true,shadow:true,buttonNav:'bullets'});
var cnt = 0;
$(".nextButton").click(function () {
var len = $(this).siblings(".slides").children(".slideItem").length;
var a = cnt++;
});
});
</script>
答案 0 :(得分:1)
除了图书馆提供的属性外,
您可以根据两个css属性选择最顶层的项目:
top
= 0px
z-index
= <Total Slides-1>
所以下面的代码片段应该这样做(并且也更新标题):
var $items = $(".slides").find(".slideItem");
$(".nextButton, .prevButton").click(function () {
$("#title").text($items.filter(function () {
return $(this).css("top") == "0px";
}).find("a").attr("title"));
});
这是你的updated fiddle。
答案 1 :(得分:0)
根据youtube API v2,
> The API response for a playlist feed is almost identical to a typical
> video feed or set of search results. However, a video entry in a
> playlist feed differs from a typical video entry in the following
> ways:
>
> Each playlist entry contains the <yt:position> tag, which specifies
> the place that the video appears in the playlist order. The
> <yt:position> tag is a subtag of the <entry> tag.
>
> If the user defined a custom title for the video, that title appears
> in the <atom:title> tag, and the video's original title appears in the
> <media:title> tag.
因此问题的解决方案是获得yt:收到的JSON标题的位置 把你的下一个按钮挂到yt:下一个兄弟的位置和前一个兄弟的前一个按钮。 您也可以有创意,并根据此随机播放视频。