简体   繁体   English

onmouseover 和 onmouseout 帮助 - 无法持续执行

[英]onmouseover & onmouseout help - unable to continually to do it

This is my code, I am trying to make so when I hover over the image it plays a video, and when you hover off it stops the video and goes back to the original image.这是我的代码,我正在尝试这样做,当我 hover 在图像上播放视频时,当你 hover 关闭时它停止视频并返回到原始图像。 The issue is when I hover off I am not able to rehover again to play the video again.问题是当我关闭 hover 时,我无法再次悬停以再次播放视频。 I was wondering how I can do this so that I can hover over the image more than once to play the video.我想知道如何才能做到这一点,以便我可以 hover 在图像上不止一次播放视频。 My coding is below:我的编码如下:

<div class="thumb">
  <video width="450" height="450" poster="assets/img/product/mac-flower.png" loop="true" preload="auto" onmouseover="this.play()" onmouseout="this.src='assets/img/product/mac-flower.png';">
    <source src="assets/img/vid/mac-flower.MP4" type="video/mp4">
  </video>
</div>

You can try to reload video onmouseout event, so that video shows poster again and replays onmouseover.您可以尝试重新加载视频 onmouseout 事件,以便视频再次显示海报并在鼠标悬停时重播。

New Code:新代码:

<div class="thumb">
  <video width="450" height="450" poster="assets/img/product/mac-flower.png" loop="true" preload="auto" onmouseover="this.play()"onmouseout="this.load()">
    <source src="assets/img/vid/mac-flower.MP4" type="video/mp4">
  </video>
</div>

Please load poster onmouseout like this:请像这样在 mouseout 上加载海报:

<div class="thumb">
      <video width="450" height="450" poster="assets/img/product/mac-flower.png" loop="true" preload="auto" onmouseover="this.play()" onmouseout="this.load()">
        <source src="assets/img/vid/mac-flower.MP4" type="video/mp4">
      </video>
    </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM