Hi everyone,
I’d like to make my videos start to play when you hover over the text. I managed with one video so far with this script in the footer:
<script>
$(document).ready(function() {
$('.video').each(function(i, obj) {
$(this).on("mouseover", function() { hoverVideo(i); });
$(this).on("mouseout", function() { hideVideo(i); });
});
});
function hoverVideo(i) {
$('.thevideo')[i].play();
}
function hideVideo(i) {
$('.thevideo')[i].currentTime = 0;
$('.thevideo')[i].pause();
}
</script>
Putting the text in a div called »video« to start the script and the video in an html embed code like this:
<div class="video" >
<HTML Embed>
<video class="thevideo" position= "absolute" top= "0px" margin= "0 auto" height= "auto" width= "100%" preload="auto" muted loop>
<source src="https://player.vimeo.com/external/521879644.hd.mp4?s=a4bd4e1abe4608d5c07d775d5dbb3b3d55b542ff&profile_id=175" type='video/mp4;' />
</video>
</>
</div>
BUT this only seems to work with one video. If I put more videos on the side, only the first will start on hover. I tried naming my script and div class »video1« »video2« and so on but it didn’t work.
Do you have any ideas how to fix that?
Here is my site Read-Only: https://monkeyberlin-preview-3a28-d94aa03c105a2.webflow.io/
BR,
Maria`
Preformatted text
`