gpt4 book ai didi

javascript - 如何在JS中设置YouTube主题参数?

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

我一直在用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>

最佳答案

主题需要对字符串值进行赋值,因此请尝试以下操作:

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

关于javascript - 如何在JS中设置YouTube主题参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23272757/

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