I have the following conundrum.
I have an unordered list and each li consists of three elements.
The bottom element is a short video that plays once the user’s mouse is over it and resets/pauses once it has moved away.
Above it, I have a div that is black with 50% opacity (cardOverlay).
And on top of it I have another div with text. (cardOverlayText)
I am trying to get the effect where on mouseover, the opacity goes of cardOverlay goes to a higher percentage and go back to 50% if the mouse moves away.
The problem is that in order to get a bright white text in the cardOverlayText, I have to put it with higher z-index, but that also blocks the video from detecting onmouseover trigger.
In addition, I can’t figure out how to change the opacity of the cardOverlay on mouseover as well.
Here is the relevant part of the code:
<div id="SolutionCards">
<ul class="Cards">
<li class="Card">
<div class="cardOverlayText"> Sea Freight
</div>
<div class="cardOverlay"></div>
<video onmouseover="this.play();" onmouseout="this.pause();this.currentTime=0;" width="200" height="300" muted loop id="seaCardVideo">
<source src="video assets/sea card video_Trim.mp4" type="video/mp4">
</video>
</li>
...
There are total of 5
2
Answers
Try
When you add this line, the div shouldn’t "catch" the cursor. You will be able to see the element, but you won’t be able to interact with it (for example, you won’t be able to select the text).
Could you explain the problem with the cardOverlay opacity? I think the best option is to do this in CSS.
Edit:
Do you mean something like this?
Why not just use JavaScript to achieve this? You’re already running inline JS with
video.play()
andvideo.pause()
.This function will give this functionality to all of your video elements, so you don’t have to write inline JS.
The eventlistener is attached to the
.card
-element itself, but you can just swap outdocument.querySelectorAll('.Card');
with
document.querySelectorAll('.cardOverlay');
if you prefer (would suggest sticking with
.card
, though).