【问题标题】:HTML5 Video - On Hover / Off Hover return to poster image?HTML5 视频 - 悬停/悬停返回海报图像?
【发布时间】:2013-06-05 21:46:31
【问题描述】:

我正在使用 html5 视频进行沙盒实验,我想知道一旦最终用户将鼠标悬停在视频之外,我如何才能让海报图像再次显示?

我有视频设置,因此如果您将鼠标悬停在视频上可以自动播放,如果您将鼠标悬停它会停止。我希望它返回海报图像。

Javascript

<script>

document.addEventListener('mouseover',hoverVideo,false);
var vid = document.getElementById('vid1');

function hoverVideo(a)
{    
    if(a.target == vid)
    {
        vid.play();
        this.addEventListener('mouseout',hideVideo,false);
    }

}
function hideVideo(e)
{
    if(e.target == vid)
    {
        vid.pause();
    }

}

</script>

HTML5

<video id="vid1" width="1000" height="418" 
poster="poster.png" loop="true" preload="auto"
controls class="video-js vjs-default-skin">

 <source src="my_video.mp4" type='video/mp4' >
 <source src="my_video.webm" type='video/webm' />
 <source src="my_video.ogv" type='video/ogg' />

</video>    

【问题讨论】:

    标签: html video


    【解决方案1】:

    试试这个(你需要包含 jQuery)

    function hideVideo(e)
    {
        if(e.target == vid)
        {
            vid.pause();
            var poster = $(vid).attr("poster");
            $(vid).attr("poster", "");
            $(vid).attr("poster", poster);
        }
    
    }
    

    【讨论】:

    • 谢谢!就这么干的!我不得不更改 $("#vid1").attra("poster", "imageurl");,但问题是当我再次将鼠标悬停在图像上时,视频消失了。
    猜你喜欢
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    相关资源
    最近更新 更多