我一直在使用Javascript嵌入youtube播放列表,但我无法将主题更改为浅色。所有其他参数都有效,但这个参数没有通过。
这就是认为它应该如何运作:
var defoptions = {
autoplay: false,
user: null,
playlist: null,
carousel: createCarousel,
player: createPlayer,
thumbnail: createThumbnail,
max_results: 25, // does not apply to playlists
loaded: function () {},
playopts: {
autoplay: 0,
egm: 1,
autohide: 1,
fs: 1,
showinfo: 0,
rel: 0,
theme: light
}
};
有什么想法吗?
谢谢!
在这里你有完整的东西,它还远没有完成,但首先我需要找出如何改变主题。
<style>
#container{
background-color: #F1F1F1;
padding: 20px;
}
.yt-descript{
max-width: 100px;
font-family: verdana;
font-weight: bold;
font-size: 9pt;
margin: 2px;
}
.player {
width: 100%;
height: 305px;
overflow: hidden;
background-color: #F1F1F1 ;
position: relative;
}
.youtube .carousel {
width: 20%;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
position: absolute;
right: 0px;
z-index: 3;
}
.youtube .thumbnail {
margin-left: 2px;
width: 90%;
border: 1px solid black;
}
.youtube iframe.player {
width: 80%;
height: 100%;
overflow: auto;
border: 0;
}
</style>
<script>
(function () {
function createPlayer(jqe, video, options) {
var ifr = $('iframe', jqe);
if (ifr.length === 0) {
ifr = $('<iframe scrolling="no">');
ifr.addClass('player');
}
var src = 'http://www.youtube.com/embed/' + video.id;
if (options.playopts) {
src += '?';
for (var k in options.playopts) {
src += k + '=' + options.playopts[k] + '&';
}
src += '_a=b';
}
ifr.attr('src', src);
jqe.append(ifr);
}
function createCarousel(jqe, videos, options) {
var car = $('div.carousel', jqe);
if (car.length === 0) {
car = $('<div>');
car.addClass('carousel');
jqe.append(car);
}
$.each(videos, function (i, video) {
options.thumbnail(car, video, options);
});
}
function createThumbnail(jqe, video, options) {
var imgurl = video.thumbnails[0].url;
var img = $('img[src="' + imgurl + '"]');
var desc;
var container;
if (img.length !== 0) return;
img = $('<img align="left">');
img.addClass('thumbnail');
jqe.append(img);
img.attr('src', imgurl);
img.attr('title', video.title);
img.click(function () {
options.player(options.maindiv, video, $.extend(true, {}, options, {
playopts: {
autoplay: 1
}
}));
});
desk = $('<p class="yt-descript">' + video.title + '</p>');
jqe.append(desk);
desk.click(function () {
options.player(options.maindiv, video, $.extend(true, {}, options, {
playopts: {
autoplay: 1
}
}));
});
}
var defoptions = {
autoplay: false,
user: null,
playlist: null,
carousel: createCarousel,
player: createPlayer,
thumbnail: createThumbnail,
max_results: 25, // does not apply to playlists
loaded: function () {},
playopts: {
autoplay: 0,
egm: 1,
autohide: 1,
fs: 1,
showinfo: 0,
rel: 0
}
};
$.fn.extend({
youTubeChannel: function (options) {
var md = $(this);
md.addClass('youtube');
md.addClass('youtube-channel');
var allopts = $.extend(true, {}, defoptions, options);
allopts.maindiv = md;
var JSONurl = "";
if (allopts.playlist) {
JSONurl = 'http://gdata.youtube.com/feeds/api/playlists/' + allopts.playlist + '?alt=json-in-script&format=5&callback=?';
} else if (allopts.user) {
JSONurl = 'http://gdata.youtube.com/feeds/users/' + allopts.user + '/uploads?alt=json-in-script&max-results=' + allopts.max_results.toString() + '&format=5&callback=?';
} else {
console.log('user or playlist must be specified');
}
$.getJSON(JSONurl, null, function (data) {
var feed = data.feed;
var videos = [];
$.each(feed.entry, function (i, entry) {
var video = {
title: entry.title.$t,
id: entry.link[3].href.match('[^/]*$'),
thumbnails: entry.media$group.media$thumbnail
};
videos.push(video);
});
allopts.allvideos = videos;
allopts.carousel(md, videos, allopts);
allopts.player(md, videos[0], allopts);
allopts.loaded(videos, allopts);
});
}
});
})();
// Playlist
$(function () {
$('#player1').youTubeChannel({
playlist: 'PLFE3E2A9A3BDD70BE'
});
});
// Channel
$(function () {
$('#player3').youTubeChannel({
user: 'YTusername',
max_results: 50
});
});
</script>
<div id="container">
<h1>Latest Videos</h1>
<div id="player1" class="player"></div>
</div>
答案 0 :(得分:0)
主题需要对字符串值进行评估,因此请尝试以下操作:
var defoptions = {
autoplay: false,
user: null,
playlist: null,
carousel: createCarousel,
player: createPlayer,
thumbnail: createThumbnail,
max_results: 25, // does not apply to playlists
loaded: function () {},
playopts: {
autoplay: 0,
egm: 1,
autohide: 1,
fs: 1,
showinfo: 0,
rel: 0,
theme: "light",
color: "white"
}
};