<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 播放器?

        How to pause a YouTube player when hiding the iframe?(隐藏 iframe 时如何暂停 YouTube 播放器?)
              <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 播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  Embed YouTube video - Refused to display in a frame because it set #39;X-Frame-Options#39; to #39;SAMEORIGIN#39;(嵌入 YouTube 视频 - 拒绝显示在框架中,因为它将“X-Frame-Options设置为“SAMEORIGIN)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)

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

                        • <small id='6RVrL'></small><noframes id='6RVrL'>

                          <legend id='6RVrL'><style id='6RVrL'><dir id='6RVrL'><q id='6RVrL'></q></dir></style></legend>
                            <tbody id='6RVrL'></tbody>
                          • <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>