javascript
  • jquery
  • json
  • youtube-api
  • 2013-02-23 64 views 0 likes 
    0

    我正在將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> 
    

    這裏是演示鏈接http://jsfiddle.net/EzKQy/

    回答

    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

    +0

    非常感謝:)。你解決了我的問題 – 2013-02-24 18:26:03

    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:下一個兄弟和前一個按鈕到上一個兄弟的位置。 你也可以富有創意,並根據這一點隨機洗視頻。

    由圖書館提供的性能
    相關問題