Youtube视频叠加?

时间:2017-04-23 14:35:23

标签: javascript jquery html css youtube

因此,当您点击播放链接时,我一直试图弄清楚如何使用youtube视频叠加英雄形象(因此视频会填充div的高度和宽度)。但我不知道该怎么做。我尝试过使用弹出插件,但我不认为他们是解决方案。我试图完成这些人在他们网站上的所作所为:https://www.squarespace.com/ 但因为我是一个菜鸟,我无法阅读他们所做的事情。

我该怎么办?使用div覆盖youtube视频,或?我也需要jQuery吗?有人,帮忙!

谢谢!

编辑: 我尝试过使用Magnific Popup。但我无法使其发挥作用。无论如何,这是我尝试过的:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>

<a class="video" href="https://www.youtube.com/watch?v=LGZaWik2430">Click To View</a>

$('.video').magnificPopup({
  type: 'iframe',


  iframe: {
     markup: '<div class="mfp-iframe-scaler">'+
                '<div class="mfp-close"></div>'+
                '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>' +
              '</div>'
  },
  callbacks: {
    markupParse: function(template, values, item) {
     values.title = item.el.attr('title');
    }
  }


});

2 个答案:

答案 0 :(得分:1)

首先,视频,尺寸,甚至悬停动画和背景图像,叠加按钮等的位置都可以使用CSS完成。我没有看到需要使用javascript。

对于视频播放,也可以使用CSS调整背景图像的大小,您可以根据需要设置播放选项。

答案 1 :(得分:0)

您可以使用W3 Schools将视频插入模式。您可以使用图像而不是模态按钮。这是我得到的:

// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
<h2>Modal Example</h2>

<!-- Trigger/Open The Modal -->
<button id="myBtn"><img src="IMAGE URL" height="50px" width="50px" alt="YOUR IMAGE"></button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p>Your Video Here</p>
  </div>

</div>

相关问题