简体   繁体   中英

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? 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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