【问题标题】:Hover a html5 player doesn't work in chrome将 html5 播放器悬停在 chrome 中不起作用
【发布时间】:2012-08-11 07:25:04
【问题描述】:

我正在尝试在鼠标悬停时播放 html 5 视频。它在 Firefox 和 safari 中运行良好,只是在 chrome 中当我悬停时视频空白,只有在我将鼠标悬停在页面上的另一个元素上后才可见....

这是网站:www.manart.de

这是代码:

    <div id="wrapper">
    <video id="video-example" width="880" height="495" poster="fileadmin/cover.png" loop>
    <source src="fileadmin/schiffchen.ogg.ogv" type="video/ogg"></source>
    <source src="fileadmin/schiffchen.mp4" type="video/mp4"></source>
    </video>    
    </div><!--end wrapper-->

    <script src="fileadmin/js.js"></script>

这是js:

    document.addEventListener('mouseover',hoverVideo,false);
    var vid = document.getElementById('video-example');
    function hoverVideo(e)
    {   
    if(e.target == vid)
    {
    vid.play();
    this.addEventListener('mouseout',hideVideo,false);
    }

    }

感谢您的帮助!!!!

【问题讨论】:

    标签: html google-chrome video hover


    【解决方案1】:

    这有点奇怪,但如果你删除海报框架(我还确保定义了 hideVideo 方法以避免引发异常)它可以工作(fiddle)。

    我尝试使用JPG 而不是PNG 作为海报框架,结果相同(fiddle)。当您用声音替换视频时,很明显视频正在播放,但它是不可见的 (fiddle)。

    对我来说,这看起来像是 Chrome 中的一个错误,但当我搜索时,Google 并没有抛出太多问题(也许我的术语有误)。

    因此,快速解决方法可能是简单地删除海报框架,因为 Chrome 会在加载后显示视频的第一帧,因此可能与您正在寻找的内容非常接近。

    更新:

    或者,您可以使用thread on a similar issue 中详述的 hack,它涉及在播放开始之前向播放器动态添加控件并立即再次删除它们 (fiddle)。作者通过验证 Chrome 19 中未出现此问题,确认该问题为 Chrome 中的错误。

    HTML:

    <div id="wrapper">
        <video id="video-example" poster="http://www.manart.de/fileadmin/cover.png" width="880" height="495" loop>
          <source id='mp4'
            src="http://www.manart.de/fileadmin/schiffchen.mp4"
            type='video/mp4'>
          <source id='ogv'
            src="http://www.manart.de/fileadmin/schiffchen.ogg.ogv"
            type='video/ogg'>
        </video>    
    </div>
    

    JavaScript:

    var vid = document.getElementById('video-example');
    // add the listener directly to the video element
    vid.addEventListener('mouseover',hoverVideo,false);
    
    function hoverVideo(e) {   
        if (vid.getAttribute('controls') != 'true') {
            vid.setAttribute('controls', 'true');                    
        }
        vid.play();
        vid.removeAttribute('controls');
        vid.addEventListener('mouseout',hideVideo,false);
    }
    
    function hideVideo(e) {
        // do whatever you were going to do here, but omitting
        // the method completely causes an exception
        //vid.pause();   
    
        // clean up the listener when finished
        vid.removeEventListener('mouseout', hideVideo);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 2018-11-27
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      相关资源
      最近更新 更多