I want to hover on text and have a video appear and play when the user hovers and when you are not hovering, the video would disappear.
I found the following on codepen which does work for both images and video when hovering on specific text, but when I copy the HTML code to list another video since I don't want this for images the next video won't play. It will only play the first video listed. Please help!
function vidPlay() {
$("#video1").get(0).play();
};
function vidPause() {
$("#video1").get(0).pause();
};
$(document).ready(function(){
$("#textToggler").click(function(){
$(".toggleText").toggle();
});
});
function toggleImage() {
$(".hiddenclickimg").toggle();
};
.hiddenimg {
display: none;
}
.hiddentxt {
font-weight: bold;
color: #F00;
z-index:99;
}
.hiddentxt a {
color: #F00;
text-decoration: none;
z-index: 99;
}
.hiddenclick {
font-weight: bold;
color: #F00;
text-decoration: none;
cursor: pointer;
}
.hiddenclick a {
color: #F00;
text-decoration: none;
}
.hiddenclick a:visited {
color: #F00;
text-decoration: none;
}
.hiddentxt:hover ~ .hiddenimg {
display: block;
position: absolute;
z-index: 2
}
.hiddenclickimg {
display: none;
}
<head>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
</head>
<body>
<p>
Hover to see a <span class="hiddentxt"><a href="https://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg">banana</a></span><span class="hiddenimg"><img src="https://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg" width="250" /></span>.
</p>
<p>
Let's see if it works with <span class="hiddentxt" onmouseover="vidPlay()" onmouseout="vidPause()"><a href="https://mtc.cdn.vine.co/r/videos/ECBC329ACC1050514912117440512_1c6599f182f.4.6.16444000809832514200.mp4">videos</a></span>. (The video should play when it's displayed, but sometimes it takes a while to load.)
<span class="hiddenimg"><video id="video1" loop>
<source src="https://mtc.cdn.vine.co/r/videos/ECBC329ACC1050514912117440512_1c6599f182f.4.6.16444000809832514200.mp4" type="video/mp4">
</video></span>
</P>
<p> Click <span class = "hiddenclick" onclick = "toggleImage()">here</span> to show image.<br>
<span class="hiddenclickimg"><img src = "https://s-media-cache-ak0.pinimg.com/originals/22/74/8c/22748c9b9cc2c039aed206cab0247404.gif"/></span>
</p>
</body>