<legend id='Z9BPs'><style id='Z9BPs'><dir id='Z9BPs'><q id='Z9BPs'></q></dir></style></legend>

        • <bdo id='Z9BPs'></bdo><ul id='Z9BPs'></ul>

        <small id='Z9BPs'></small><noframes id='Z9BPs'>

        <tfoot id='Z9BPs'></tfoot>
      1. <i id='Z9BPs'><tr id='Z9BPs'><dt id='Z9BPs'><q id='Z9BPs'><span id='Z9BPs'><b id='Z9BPs'><form id='Z9BPs'><ins id='Z9BPs'></ins><ul id='Z9BPs'></ul><sub id='Z9BPs'></sub></form><legend id='Z9BPs'></legend><bdo id='Z9BPs'><pre id='Z9BPs'><center id='Z9BPs'></center></pre></bdo></b><th id='Z9BPs'></th></span></q></dt></tr></i><div id='Z9BPs'><tfoot id='Z9BPs'></tfoot><dl id='Z9BPs'><fieldset id='Z9BPs'></fieldset></dl></div>

        隐藏 iframe 时如何暂停 YouTube 播放器?

        时间:2023-09-08
              <tbody id='5VazX'></tbody>
              <bdo id='5VazX'></bdo><ul id='5VazX'></ul>
              <legend id='5VazX'><style id='5VazX'><dir id='5VazX'><q id='5VazX'></q></dir></style></legend>
              <i id='5VazX'><tr id='5VazX'><dt id='5VazX'><q id='5VazX'><span id='5VazX'><b id='5VazX'><form id='5VazX'><ins id='5VazX'></ins><ul id='5VazX'></ul><sub id='5VazX'></sub></form><legend id='5VazX'></legend><bdo id='5VazX'><pre id='5VazX'><center id='5VazX'></center></pre></bdo></b><th id='5VazX'></th></span></q></dt></tr></i><div id='5VazX'><tfoot id='5VazX'></tfoot><dl id='5VazX'><fieldset id='5VazX'></fieldset></dl></div>

                  <small id='5VazX'></small><noframes id='5VazX'>

                  <tfoot id='5VazX'></tfoot>
                1. 本文介绍了隐藏 iframe 时如何暂停 YouTube 播放器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个隐藏的 div,其中包含 <iframe> 中的 YouTube 视频.当用户点击链接时,该 div 变为可见,用户应该能够播放视频.

                  I have a hidden div containing a YouTube video in an <iframe>. When the user clicks on a link, this div becomes visible, the user should then be able to play the video.

                  当用户关闭面板时,视频应该停止播放.我怎样才能做到这一点?

                  When the user closes the panel, the video should stop playback. How can I achieve this?

                  代码:

                  <!-- link to open popupVid -->
                  <p><a href="javascript:;" onClick="document.getElementById('popupVid').style.display='';">Click here</a> to see my presenting showreel, to give you an idea of my style - usually described as authoritative, affable and and engaging.</p>
                  
                  <!-- popup and contents -->
                  <div id="popupVid" style="position:absolute;left:0px;top:87px;width:500px;background-color:#D05F27;height:auto;display:none;z-index:200;">
                  
                    <iframe width="500" height="315" src="http://www.youtube.com/embed/T39hYJAwR40" frameborder="0" allowfullscreen></iframe>
                  
                    <br /><br /> 
                    <a href="javascript:;" onClick="document.getElementById('popupVid').style.display='none';">
                    close
                    </a>
                  </div><!--end of popupVid -->
                  

                  推荐答案

                  实现此行为的最简单方法是在必要时调用 pauseVideoplayVideo 方法.灵感来自我的 以前的答案,我已经编写了一个无插件函数来实现所需的行为.

                  The easiest way to implement this behaviour is by calling the pauseVideo and playVideo methods, when necessary. Inspired by the result of my previous answer, I have written a pluginless function to achieve the desired behaviour.

                  唯一的调整:

                  • 我添加了一个函数,toggleVideo
                  • 我已将 ?enablejsapi=1 添加到 YouTube 的 URL,以启用该功能
                  • I have added a function, toggleVideo
                  • I have added ?enablejsapi=1 to YouTube's URL, to enable the feature

                  演示:http://jsfiddle.net/ZcMkt/
                  代码:

                  Demo: http://jsfiddle.net/ZcMkt/
                  Code:

                  <script>
                  function toggleVideo(state) {
                      // if state == 'hide', hide. Else: show video
                      var div = document.getElementById("popupVid");
                      var iframe = div.getElementsByTagName("iframe")[0].contentWindow;
                      div.style.display = state == 'hide' ? 'none' : '';
                      func = state == 'hide' ? 'pauseVideo' : 'playVideo';
                      iframe.postMessage('{"event":"command","func":"' + func + '","args":""}', '*');
                  }
                  </script>
                  
                  <p><a href="javascript:;" onClick="toggleVideo();">Click here</a> to see my presenting showreel, to give you an idea of my style - usually described as authoritative, affable and and engaging.</p>
                  
                  <!-- popup and contents -->
                  <div id="popupVid" style="position:absolute;left:0px;top:87px;width:500px;background-color:#D05F27;height:auto;display:none;z-index:200;">
                     <iframe width="500" height="315" src="http://www.youtube.com/embed/T39hYJAwR40?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
                     <br /><br />
                     <a href="javascript:;" onClick="toggleVideo('hide');">close</a>
                  

                  这篇关于隐藏 iframe 时如何暂停 YouTube 播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:YouTube iframe 播放器 API - OnStateChange 未触发 下一篇:出现错误 403:未配置访问.请使用 Google Developers Console 为您的项目激活 API

                  相关文章

                      <tfoot id='6RVrL'></tfoot>

                    1. <small id='6RVrL'></small><noframes id='6RVrL'>

                      <legend id='6RVrL'><style id='6RVrL'><dir id='6RVrL'><q id='6RVrL'></q></dir></style></legend>
                      • <bdo id='6RVrL'></bdo><ul id='6RVrL'></ul>

                      <i id='6RVrL'><tr id='6RVrL'><dt id='6RVrL'><q id='6RVrL'><span id='6RVrL'><b id='6RVrL'><form id='6RVrL'><ins id='6RVrL'></ins><ul id='6RVrL'></ul><sub id='6RVrL'></sub></form><legend id='6RVrL'></legend><bdo id='6RVrL'><pre id='6RVrL'><center id='6RVrL'></center></pre></bdo></b><th id='6RVrL'></th></span></q></dt></tr></i><div id='6RVrL'><tfoot id='6RVrL'></tfoot><dl id='6RVrL'><fieldset id='6RVrL'></fieldset></dl></div>