如何隐藏 YouTube 控件

How to hide YouTube Controls

我不知道如何隐藏 YouTube 的控件。

当控件设置为 1https://jsfiddle.net/ae0Lwj5f/

  managePlayer.init({
    playerVars: {
    controls: 1,

您可以在此处显示 控件

控件设置为0时, https://jsfiddle.net/nz9hxacu/

  managePlayer.init({
    playerVars: {
    controls: 0,

您可以看到 控件 仍然可见并且未隐藏

这是代码中唯一被修复的东西。

Controls 设置为 0 应该如下所示。

  managePlayer.init({
    playerVars: {
    controls: 0,

这是正在处理的代码。

代码 2: https://jsfiddle.net/ae0Lwj5f/

    const defaultOptions = defaults.playerOptions;
    const defaultVars = defaultOptions.playerVars;
    const playerVars = settings;
    const playerOptions = combinePlayerOptions(defaultOptions, settings);
    playerOptions.playerVars = Object.assign({}, defaultVars, playerVars);
    const player = new YT.Player(video, playerOptions);
    players.push(player);
    return player;
  }

以下是控件工作的示例。

这些代码正在处理中。

代码 2 添加 combinePlayerOptions 之前。 https://jsfiddle.net/zy15rLap/

使用 combinePlayerOptions 的代码 1 https://jsfiddle.net/pcgmvj7L/

在正在处理的代码中,如何修复?

在您的代码 2 中,只需添加 autoplay:0 即可隐藏您的控件。

代码 2 https://jsfiddle.net/30dk69yx/2/

function onYouTubeIframeAPIReady() {
  managePlayer.init({
    playerVars: {
    autoplay:0,
      controls: 0,
      fs: 0
    }
  });

已添加:

  function createPlayer(videoWrapper, playerOptions = {}, videoIds = "") {
    const video = videoWrapper.querySelector(".video");
    if (!videoIds) {
      videoIds = video.dataset.id;
    }
    const fixedOptions = {
      playerVars: playerOptions
    };
    playerOptions = combinePlayerOptions(defaults, fixedOptions);
    return videoPlayer.addPlayer(video, playerOptions, videoIds);
  }

https://jsfiddle.net/L6osw27b/

const manageCover = (function makeManageCover() {
  const config = {};

  function show(el) {
    el.classList.remove("hide");
  }

  function hide(el) {
    el.classList.add("hide");
  }

  function hideAll(elements) {
    elements.forEach(hide);
  }

  function showCovers(playButton) {
    const cover = playButton.parentElement;
    cover.classList.add("active");
    show(cover);
  }

  function coverClickHandler(evt) {
    hideAll(config.containers);
    const cover = evt.currentTarget;
    showCovers(cover);
  }

  function addClickToButtons(playButtons) {
    playButtons.forEach(function addEventHandler(playButton) {
      playButton.addEventListener("click", coverClickHandler);
    });
  }

  function addCoverHandler(coverSelector, handler) {
    const cover = document.querySelector(coverSelector);
    cover.addEventListener("click", handler);
  }

  function init(selectors) {
    config.containers = document.querySelectorAll(selectors.container);
    const playButtons = document.querySelectorAll(selectors.playButton);
    addClickToButtons(playButtons);
  }

  return {
    addCoverHandler,
    init,
    show
  };
}());

function combinePlayerOptions(playerOptions1 = {}, playerOptions2 = {}) {
  const combined = Object.assign({}, playerOptions1, playerOptions2);
  Object.keys(playerOptions1).forEach(function(prop) {
    if (typeof playerOptions1[prop] === "object") {
      combined[prop] = Object.assign({},
        playerOptions1[prop],
        playerOptions2[prop]
      );
    }
  });
  return combined;
}

const videoPlayer = (function makeVideoPlayer() {
  const players = [];

  const tag = document.createElement("script");
  tag.src = "https://www.youtube.com/player_api";
  const firstScriptTag = document.getElementsByTagName("script")[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  function onPlayerReady(event) {
    const player = event.target;
    player.setVolume(100); // percent
  }


  function addPlayer(video, settings, videoIds = video.dataset.id) {
    const videoId = !Array.isArray(videoIds) && videoIds;
    const playlist = Array.isArray(videoIds) && videoIds.join();
    const defaults = {

      events: {
        "onReady": onPlayerReady
      },
      height: 360,
      host: "https://www.youtube-nocookie.com",
      playerVars: {
        playlist: playlist || undefined
      },
      videoId,
      width: 640

    };


    const playerOptions = combinePlayerOptions(defaults, settings);
    const player = new YT.Player(video, playerOptions);
    players.push(player);
    return player;
  }

  return {
    addPlayer
  };
}());

const managePlayer = (function makeManagePlayer() {
  const defaults = {
    playerVars: {
      autoplay: 0,
      controls: 0,
      disablekb: 1,
      enablejsapi: 1,
      fs: 0,
      iv_load_policy: 3,
      rel: 0
    }
  };

  function show(el) {
    el.classList.remove("hide");
  }


  function createPlayer(videoWrapper, playerOptions = {}, videoIds = "") {
    const video = videoWrapper.querySelector(".video");
    if (!videoIds) {
      videoIds = video.dataset.id;
    }
    const fixedOptions = {
      playerVars: playerOptions
    };
    playerOptions = combinePlayerOptions(defaults, fixedOptions);
    return videoPlayer.addPlayer(video, playerOptions, videoIds);
  }

  function createCoverClickHandler(playerOptions, videoIds) {
    return function coverClickHandler(evt) {
      const cover = evt.currentTarget;
      const wrapper = cover.nextElementSibling;
      show(wrapper);
      const player = createPlayer(wrapper, playerOptions, videoIds);
      wrapper.player = player;
    };
  }

  function addPlayer(coverSelector, playerSettings, videoIds) {
    const clickHandler = createCoverClickHandler(playerSettings, videoIds);
    manageCover.addCoverHandler(coverSelector, clickHandler);
  }


  function addPlayerRandomVideo(coverSelector, playerSettings, videoIds) {
    const index = Math.floor(Math.random() * videoIds.length);
    const videoId = videoIds[index];
    const clickHandler = createCoverClickHandler(playerSettings, videoId);
    manageCover.addCoverHandler(coverSelector, clickHandler);
  }


  function init(playerOptions) {
    Object.assign(defaults, playerOptions);

  }

  return {
    add: addPlayer,
    addRandom: addPlayerRandomVideo,
    init
  };
}());

function onYouTubeIframeAPIReady() {
  managePlayer.init({
    playerVars: {
      controls: 1,
      fs: 0
    }
  });
  managePlayer.addRandom(".playa", {
    start: 45
  }, [
    "0dgNc5S8cLI",
    "mnfmQe8Mv1g",
    "-Xgi_way56U",
    "CHahce95B1g"
  ]);
  managePlayer.add(".playb", {}, [
    "0dgNc5S8cLI",
    "mnfmQe8Mv1g",
    "-Xgi_way56U",
    "CHahce95B1g"
  ]);
  managePlayer.add(".playc", {
    start: 60
  });
  manageCover.init({
    container: ".container",
    playButton: ".thePlay"
  });
}
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: #353198;
  animation: fade 2s ease 0s forwards;
}
@keyframes fade {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
.outer {
  display: flex;
  min-height: 100%;
  box-sizing: border-box;
  justify-content: center;
}
.container {
  display: flex;
  justify-content: center;
}
.container.active {
  flex: 1 0 0;
  animation: fadebody 5s ease 0s forwards;
  background-size: 165px 165px;
  background-image: linear-gradient(teal 5px, #0000 5px),
    linear-gradient(90deg, teal 5px, #0000 5px),
    linear-gradient(black 10px, #0000 10px 160px, black 160px),
    linear-gradient(90deg, black 10px, #0000 10px 160px, black 160px),
    linear-gradient(orange 15px, #0000 15px 155px, orange 155px),
    linear-gradient(90deg, orange 15px, #0000 15px 155px, orange 155px),
    linear-gradient(black 20px, #0000 20px 150px, black 150px),
    linear-gradient(90deg, black 20px, #0000 20px 150px, black 150px),
    linear-gradient(teal 25px, #0000 25px 145px, teal 145px),
    linear-gradient(90deg, teal 25px, #0000 25px 145px, teal 145px),
    linear-gradient(black 30px, #0000 30px 140px, black 140px),
    linear-gradient(90deg, black 30px, #0000 30px 140px, black 140px),
    linear-gradient(orange 35px, #0000 35px 135px, orange 135px),
    linear-gradient(90deg, orange 35px, #0000 35px 135px, orange 135px),
    linear-gradient(black 40px, #0000 40px 130px, black 130px),
    linear-gradient(90deg, black 40px, #0000 40px 130px, black 130px),
    linear-gradient(teal 45px, #0000 45px 125px, teal 125px),
    linear-gradient(90deg, teal 45px, #0000 45px 125px, teal 125px),
    linear-gradient(black 50px, #0000 50px 120px, black 120px),
    linear-gradient(90deg, black 50px, #0000 50px 120px, black 120px),
    linear-gradient(orange 55px, #0000 55px 115px, orange 115px),
    linear-gradient(90deg, orange 55px, #0000 55px 115px, orange 115px),
    linear-gradient(black 60px, #0000 60px 110px, black 110px),
    linear-gradient(90deg, black 60px, #0000 60px 110px, black 110px),
    linear-gradient(teal 65px, #0000 65px 105px, teal 105px),
    linear-gradient(90deg, teal 65px, #0000 65px 105px, teal 105px),
    linear-gradient(black 70px, #0000 70px 100px, black 100px),
    linear-gradient(90deg, black 70px, #0000 70px 100px, black 100px),
    linear-gradient(orange 75px, #0000 75px 95px, orange 95px),
    linear-gradient(90deg, orange 75px, #0000 75px 95px, orange 95px),
    linear-gradient(black 80px, #0000 80px 90px, black 90px),
    linear-gradient(90deg, black 80px, #0000 80px 90px, black 90px),
    linear-gradient(teal, teal);
}
/* when container is active hide the svg */
.container.active .thePlay {
  display: none;
}

.inner-container {
  display: none;
}
/* when container is active hide the svg and show the inner container*/
.container.active .thePlay {
  display: none;
}
.container.active .inner-container {
  display: flex;
}
.container.active .inner-container.curtain {
  display: block;
}

@keyframes fadebody {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.playa,
.playb,
.playc {
  margin: auto 20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
}

.playa {
  fill: red;
  filter: drop-shadow(3px 3px 3px rgba(0, 0, 0, 0.7));
}

.playb {
  fill: blue;
  filter: drop-shadow(3px 3px 3px rgba(0, 0, 0, 0.7));
}

.playc {
  fill: orange;
  filter: drop-shadow(3px 3px 3px rgba(0, 0, 0, 0.7));
}

.curtain {
  position: relative;
  max-width: 640px;
  margin: auto;
  flex: 1 0 0%;
}
.panel-left,
.panel-right {
  position: absolute;
  height: 100%;
  width: calc(50% + 1px); /* rounding error fix */
  top: 0%;
  transition: all ease 10s;

  /*background-image: url("https://picsum.photos/600");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;*/
  overflow: hidden;
}

.panel-left {
  left: 0;
  /*background-color: rgb(91, 96, 106);*/
}

.panel-right {
  right: 0;
  /*background-color: rgb(229, 211, 211);*/
}

.panel-left::before,
.panel-right::before {
  content: "";
  position: absolute;
  height: 100%;
  width: 200%;
  top: 0;
  left: 0;
  background-image: url("https://picsum.photos/id/26/1920/1080");
  background-size: auto;
  background-repeat: no-repeat;
  background-position: 0 0;
}
.curtain2 .panel-left::before,
.curtain2 .panel-right::before {
  background-image: url("https://picsum.photos/id/27/1920/1080");
}

.panel-right::before {
  left: -100%;
}

.container.active .curtain .panel-left {
  animation: curtain1 8s forwards;
  animation-delay: 1s;
}

@keyframes curtain1 {
  to {
    transform: translateX(-100%);
  }
}

.container.active .curtain .panel-right {
  animation: curtain2 8s forwards;
  animation-delay: 1s;
}

@keyframes curtain2 {
  to {
    transform: translateX(100%);
  }
}

.ratio-keeper {
  position: relative;
  height: 0;
  padding-top: 56.25%;
  border-radius: 25px;
  margin: auto;
  overflow: hidden;
}

.video-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.hide {
  display: none;
}
<div class="outer">
    <div class="container with-curtain">
        <svg class="playa thePlay" width="100%" height="100%" viewBox="0 0 64 64">
            <path d="M25.6,46.4L44.8,32L25.6,17.6V46.4z M32,0C14.3,0,0,14.3,0,32s14.3,32,32,32s32-14.3,32-32S49.7,0,32,0z
      M32,57.6C17.9,57.6,6.4,46.1,6.4,32S17.9,6.4,32,6.4S57.6,17.9,57.6,32S46.1,57.6,32,57.6z" />
        </svg>
        <div class="inner-container curtain curtain1">
            <div class="ratio-keeper">
                <div class="wrapa">
                    <div class="video video-frame"></div>
                </div>
                <div class="panel-left"></div>
                <div class="panel-right"></div>
            </div>
        </div>
    </div>

    <div class="container with-curtain">
        <svg class="playb thePlay " width="100%" height="100%" viewBox="0 0 64 64">
            <path d="M25.6,46.4L44.8,32L25.6,17.6V46.4z M32,0C14.3,0,0,14.3,0,32s14.3,32,32,32s32-14.3,32-32S49.7,0,32,0z
      M32,57.6C17.9,57.6,6.4,46.1,6.4,32S17.9,6.4,32,6.4S57.6,17.9,57.6,32S46.1,57.6,32,57.6z" />
        </svg>
        <div class="inner-container curtain curtain2">
            <div class="ratio-keeper">
                <div class="wrapa">
                    <div class="video video-frame"></div>
                </div>
                <div class="panel-left"></div>
                <div class="panel-right"></div>
            </div>
        </div>
    </div>

    <div class="container with-curtain">
        <svg class="playc thePlay " width="100%" height="100%" viewBox="0 0 64 64">
            <path d="M25.6,46.4L44.8,32L25.6,17.6V46.4z M32,0C14.3,0,0,14.3,0,32s14.3,32,32,32s32-14.3,32-32S49.7,0,32,0z
      M32,57.6C17.9,57.6,6.4,46.1,6.4,32S17.9,6.4,32,6.4S57.6,17.9,57.6,32S46.1,57.6,32,57.6z" />
        </svg>
        <div class="inner-container curtain curtain3">
            <div class="ratio-keeper">
                <div class="wrapa">
                    <div class="video video-frame" data-id="qe5WF4qCSkQ"></div>
                </div>
                <div class="panel-left"></div>
                <div class="panel-right"></div>
            </div>
        </div>
    </div>
</div>