I'm trying to make a gallery of videos that play on hover...and only when hovered. But for some reason, sometimes the videos continue to play even when the mouse exits them.
I'm using aurelia's mouseover.delegate="hoverVideo($index)"
and mouseout.delegate="hideVideo($index)"
to initiate the playback.
hoverVideo = index => {
let id = "#video" + "-" + index.toString();
let isPlaying =
$(id).get(0).currentTime > 0 &&
!$(id).get(0).paused &&
!$(id).get(0).ended &&
$(id).get(0).readyState > 2;
if (!isPlaying) {
$(id)
.get(0)
.play();
}
};
hideVideo = index => {
let id = "#video" + "-" + index.toString();
let isPlaying =
$(id).get(0).currentTime > 0 &&
!$(id).get(0).paused &&
!$(id).get(0).ended &&
$(id).get(0).readyState > 2;
if (isPlaying) {
$(id)
.get(0)
.pause();
}
};
How do I get the videos to ALWAYS stop playing on mouse exit?