0

我正在将 Youtube 视频提取到具有下一个和上一个按钮的轮播中。我还添加了演示链接..

如何更改“下一个”和“上一个”按钮的标题、描述、总浏览量?

    <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>

这是演示链接http://jsfiddle.net/EzKQy/

4

2 回答 2

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"));
});

这是你更新的小提琴

于 2013-02-24T04:18:49.837 回答
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.

因此,该问题的解决方案是从收到的 JSON 中获取标题的 yt:position 将您的下一个按钮挂钩到下一个兄弟的 yt:position 和上一个按钮到上一个兄弟的位置。您也可以有创意,并以此为基础随机播放视频。

于 2013-02-23T19:39:02.800 回答