简体   繁体   English

使用Javascript将mousemove侦听器添加到视频元素的控件中

[英]Adding a mousemove listener to the controls of a video element with Javascript

basically I've got a basic video element 基本上我有一个基本的视频元素

<video width="320" height="240" controls>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

Is there a non-jQuery way to add a listener to the controls of a video element? 是否有非jQuery的方法将侦听器添加到视频元素的控件中? the controls, as you know, will look like this on different browsers: 如您所知,控件在不同的浏览器中将如下所示:

在此处输入图片说明

All I need is a function to run once a user hover over that. 我需要的是一个一旦用户将鼠标悬停在其上即可运行的函数。

Edit: I also need a function that will run once a user moves out of the controls 编辑:我还需要一个功能,一旦用户移出控件,该功能便会运行

To add a mouse over event to an object, you can use the following code: 要将鼠标悬停事件添加到对象,可以使用以下代码:

yourobject.addEventListener("mouseover", function() {
    //whatever you want to do
}); 

To add a mouse out event to an object, you can use the following code: 要将鼠标移出事件添加到对象,可以使用以下代码:

yourobject.addEventListener("mouseout", function() {
    //whatever you want to do
}); 

References: 参考文献:

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

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