How to play video on hover (in 25% width increments) - html

I recently found this question:
How to hide video on div hover?
And it perfectly shows what I need for a website right now.
My question is,
is this possible with 4 videos as well, or is that strecthing it?
I would need every quarter of the video with to display a different (short) video.
Unfortunately I'm still a beginner in HTML and CSS so I hope someone can help me with this
The code from the answer on the original thread is posted below.
$('.video_wrapper .video_hover').hover(function() {
$('.video_wrapper').addClass('isHover');
}, function() {
$('.video_wrapper').removeClass('isHover');
});
.video_wrapper {
overflow: hidden;
position: relative;
}
.video_wrapper video {
height: auto;
width: 100vw;
}
.video_wrapper .eat_video {
left: 0;
opacity: 0;
position: absolute;
top: 0;
}
.video_wrapper .video_hover {
bottom: 0;
cursor: pointer;
position: absolute;
right: 0;
top: 0;
width: 50%;
z-index: 1;
}
.video_wrapper .live_video,
.video_wrapper .eat_video {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.video_wrapper.isHover .live_video {
opacity: 0;
}
.video_wrapper.isHover .eat_video {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class=video_wrapper>
<div class="live_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" >
</video>
</div>
<div class="eat_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4" type="video/mp4" >
</video>
</div>
<div class="video_hover"></div>
</div>

Welcome to Stackoverflow Jos,You can use mouse enter and leave event to achive this.
const video = document.getElementById('myvideo');
video.onmouseenter = function(){
if(video.paused){
video.play();
}
}
video.onmouseleave = function(){
if(!video.paused){
video.pause();
}
}
.video_wrapper{
overflow: hidden;
position: relative;
}
.video_wrapper video{
height: auto;
display:block;
margin:auto;
}
.video_wrapper .eat_video{
left: 0;
opacity: 0;
position: absolute;
top: 0;
}
.video_wrapper .video_hover{
bottom: 0;
cursor: pointer;
position: absolute;
right: 0;
top: 0;
width: 50%;
z-index: 1;
}
.video_wrapper .live_video,
.video_wrapper .eat_video{
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#myvideo:hover{
cursor:pointer;
transform:scale(1.25);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class=video_wrapper>
<div class="live_video">
<video loop muted class="video" id = 'myvideo' preload="auto">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" >
</video>
</div>
</div>

"How to play video on hover (in 25% width increments)"
In HTML...
Create a <div> that is a container for your four <video> tags.
In Javascript...
Add a mousemove listener to your Div and then extract the mouse X position into some variable.
Divide the width (eg: from .clientWidth value) of the Div by 4 (to get the required four 25%).
When the mouse moves you check the X-pos variable to see which quadrant the pointer is at. This means using ratios and modulo operator to get a number result between 1 and 4.
Use the result number to tell a specific video tag to be .visble (and the rest become .hidden).
PS: I recommend also having a text on screen to show the number for the mouse position over the Div, so you can see what the computer sees. Use a Div's .innerHTML or .innerText to add text.
Update your code with a specific attempt at the above-listed points and I will help you with the part(s) where you're stuck. Ask anything when in doubt about your video/mouse code's issues.

I am sure that this is exactly what you're looking for. : )
Hope this helps.
$('.video_wrapper').on("mousemove", function (event) {
if(event.pageY <= $('.video_wrapper').height()){
if(event.pageX <= $('.video_wrapper').width()/4){
$('.video_clip').removeClass('isHover');
$('.first_video').addClass('isHover');
} else if(event.pageX <= $('.video_wrapper').width()/2){
$('.video_clip').removeClass('isHover');
$('.second_video').addClass('isHover');
} else if(event.pageX <= $('.video_wrapper').width()*3/4){
$('.video_clip').removeClass('isHover');
$('.third_video').addClass('isHover');
} else {
$('.video_clip').removeClass('isHover');
$('.fourth_video').addClass('isHover');
}
}
});
$('.video_wrapper').on("mouseleave", function (event) {
$('.video_clip').removeClass('isHover');
$('.first_video').addClass('isHover');
});
.video_wrapper {
overflow: hidden;
position: relative;
}
.video_wrapper video {
height: auto;
width: 100vw;
}
.video_wrapper .video_clip:not(.first_video) {
left: 0;
opacity: 0;
position: absolute;
top: 0;
}
.video_wrapper .video_clip {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.video_wrapper .video_clip {
opacity: 0;
}
.video_wrapper .isHover.video_clip {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class=video_wrapper>
<div class="video_clip first_video isHover">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" >
</video>
</div>
<div class="video_clip second_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4" type="video/mp4" >
</video>
</div>
<div class="video_clip third_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" >
</video>
</div>
<div class="video_clip fourth_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4" type="video/mp4" >
</video>
</div>
</div>

Related

Can't change video's opacity in reactjs

I would like to add some green opacity to my react video, but fail to to do.
I tried with adding background-color: rgba(0, 255, 0, 0.3) to each of the divs, but nothing is helping me out.
Using the latest version of Chrome.
Can someone help me out with this?
Here is my code:
<div className="intro__video fadeIn">
<video className="intro__video__content" autoPlay muted loop>
<source src={bgVideo} type="video/mp4" />
<source src="img/video.webm" type="video/webm" />
Your browser is not supported!
</video>
</div>
and my css:
intro__video {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
opacity: .15;
overflow: hidden;
&__content {
height: 100%;
width: 100%;
object-fit: cover;
// opacity: .85;
background-color: rgba(0, 255, 0, 0.3);
}
}
}
with the commented out opacity it works. But background does not. Why?
The opacity describes how opaque the whole element is: Including its descendants and content.
The background-colour describes the colour in the background of the element. The descendants and content are rendered on top of it.
If you want to use a background colour to shade an element, you have to set the background colour on something in front of the content you want to shade.
You might want to look at SVG filters instead.

Play HTML Video after CSS Animation

This is a bit crazy, but I got a project where I couldn't use JS.
I have an mp4 that needs only to be played after the CSS animation is finished.
To be better explained, I need to hide the cover image, then play the video behind it.
Is there a way to play mp4 from CSS/HTML only?
HTML
<div class="chute-background-image" style="background-image: url(./fg_bg.png);"></div>
<div class="winning-video">
<video>
<source src="./room.mp4" type="video/mp4">
</video>
</div>
CSS
.chute-background-image {
opacity: 1;
animation: hide 1s linear forwards;
}
#keyframes hide {
0% {
opacity: 1;
display: block;
}
99% {
opacity: 0;
display: block;
}
100% {
opacity: 0;
display: none;
}
}
No, it isn't possible to do this without JavaScript.
No play control API is available by CSS.

Use existing hover CSS class to other html tags

I have a hover effect over some of my images.
At the moment the hover effect is active on the figure tag. I have now added a picture tag.
Is it possible to add the same CSS to the picture tag from the existing CSS, instead of have to write the whole CSS with the only change of adding pciture instead off figure.
figure{
margin: 0;
padding: 0;
background: #fff;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Opacity for banner? */
.hover5 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: 0.8s ease-in-out;
}
.hover5 figure:hover img {
opacity: .5;
}
<div class="hover5 column">
<figure>
<img src="https://placehold.it/425x218" alt="#" class="img-responsive"></img>
</figure>
</div>
<div class="hover5 column">
<picture>
<source media="(min-width: 650px)" srcset="https://placehold.it/300x244"></source>
<source media="(min-width: 320px)" srcset="https://placehold.it/300x320"></source>
<img src="https://placehold.it/300x244" alt="#" style="width:100%;"></img>
</picture>
</div>
Instead of using figure or picture you could use a more general selector: > *. This will target the child of .hover5 no matter what element type it is.
.hover5 > *{
margin: 0;
padding: 0;
background: #fff;
}
.hover5 > *:hover+span {
bottom: -36px;
opacity: 1;
}
/* Opacity for banner? */
.hover5 > * img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: 0.8s ease-in-out;
}
.hover5 > *:hover img {
opacity: .5;
}
<div class="hover5 column">
<figure>
<img src="https://placehold.it/425x218" alt="#" class="img-responsive"></img>
</figure>
</div>
<div class="hover5 column">
<picture>
<source media="(min-width: 650px)" srcset="https://placehold.it/300x244"></source>
<source media="(min-width: 320px)" srcset="https://placehold.it/300x320"></source>
<img src="https://placehold.it/300x244" alt="#" style="width:100%;"></img>
</picture>
</div>
Where possible try to avoid targeting the HTML element's specifically. Build up a set of class names that you can put any element.
.your-hover-style:hover {
}
Or if you have to target the HTML element, then you can comma separate them.
figure, picture {
}
figure{
margin: 0;
padding: 0;
background: #fff;
}
/* Opacity for banner? */
img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: 0.8s ease-in-out;
}
img:hover {
opacity: .5;
}
<figure>
<img src="https://placehold.it/425x218" alt="#" class="img-responsive"/>
</figure>
<picture>
<source media="(min-width: 650px)" srcset="https://placehold.it/1200x400"/>
<source media="(min-width: 320px)" srcset="https://placehold.it/380x500"/>
<img src="https://placehold.it/1200x400" alt="#" style="width:100%;"/>
</picture>
Best option is to make a custom CSS class for this effect.
Let's call this class 'effect'. You can replace all the figure references in your CSS with .effect. And in your HTML turn the <figure> into <figure class="effect"> and <picture> into <picture class="effect">

Need to trigger text scroll with start of audio file

Currently I have different audio files displayed using tables in html5 and css. In each cell with the audio file is text which has artist information etc. What I want to happen is the text to scroll within the cell only when that particular audio file is playing. Right now I can make the text scroll using the marquee feature but I can't figure out how to make it only scroll when only that audio file is playing.
Note: That marquee is deprecated...
But to solve this specific problem if it's going to be executed in a supported browsers
See snippet
marq = document.getElementById("marq");;
marq.style.opacity = "0";
aud = document.getElementById("aud");;
aud.onplay = function() {
marq.style.display = "auto";
marq.start();
marq.style.opacity = "1";
}
aud.onpause = function() {
marq.stop();
}
<td>
<center>
<img src="images/artists/Becca.png" width="110" heigth="110">
<marquee id="marq" behavior="" direction="left">Becca - Trap (J Paul Mix)</marquee>
<audio controls id="aud">
<source src="http://mp3-pesni.org/music/3dc9ed0908d29016e2d41e8abb0a31fd.mp3" type="audio/mp3">
<p>Your browser doesn't support HTML5 audio. Here is alink to the audioinstead.</p>
</audio>
</center>
</td>
Nevertheless, I advise that you use css3 animation to mimic that marquee tag
See snippet below
var title = document.getElementById("title");
aud = document.getElementById("aud");;
aud.onplay = function() {
title.classList.remove('stop');
title.classList.add('running');
}
aud.onpause = function() {
title.classList.remove('running');
title.classList.add('stop');
}
#-webkit-keyframes anime {
0% {
right: 0%;
}
100% {
right: -100%;
}
}
#-moz-keyframes anime {
0% {
right: 0%;
}
100% {
right: -100%;
}
}
#-o-keyframes anime {
0% {
right: 0%;
}
100% {
right: -100%;
}
}
#keyframes anime {
0% {
right: 0%;
}
100% {
right: -100%;
}
}
#marq {
border: solid black 1px;
;
overflow: hidden;
text-align: left;
}
#title {
position: relative;
animation-name: anime;
animation-duration: 10s;
animation-iteration-count: infinite;
animation-timing-function: linear;
display: inline-block;
right: 0%;
opacity: 0;
color: green;
}
.stop {
animation-play-state: paused;
opacity: 1 !important;
}
.running {
animation-play-state: running;
opacity: 1 !important;
}
<td>
<center>
<img src="images/artists/Becca.png" width="110" heigth="110">
<div id="marq">
<div id="title">
Song 1
</div>
</div>
<audio controls id="aud">
<source src="http://mp3-pesni.org/music/3dc9ed0908d29016e2d41e8abb0a31fd.mp3" type="audio/mp3">
<p>Your browser doesn't support HTML5 audio. Here is alink to the audioinstead.</p>
</audio>
</center>
</td>

Change background-color of html5 video element

I've got the following website:
beta.leifsigersen.com
There's a movie on the front page which sometimes takes a little while to load (sometimes less than a second, sometimes a few seconds). Before the movie is loaded there's black background/borders. How can I change the color of this?
I've tried to use CSS of the video-element, but without any luck.
Try this CSS:
.pk_video {
background-color: red !important; /* or whatever you want */
}
Just add the background color to the html code itself. For example:
<video width="100%" height="100%" style="background-color: #fff;" src=""></video>
So i had this annoying white bar, I got rid of it using. I applied it the the containing div.
background-color: transparent;
Alternatively use
background-color: rgba(0, 0, 0, 0);
Hope that helps
I have used overlay content like so: Ionic/Angular
.html
<video autoplay muted loop playsinline preload="auto" onloadedmetadata="this.muted = true">
<source [src]="video" type="video/mp4" />
</video>
<div class="overlay-content"></div>
.scss
video {
object-fit: cover;
width: 100vw;
height: 60vh;
top: 0;
left: 0;
opacity: 0.5;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
.overlay-content {
position: absolute;
top: 0;
left: 0;
background: rgba(6, 56, 82, 0.5);
width: 100vw;
height: 60vh;
}