A coding noob here:)I have slick slider image carousel with both images and video. For some reason the video will only play when set to auto play. I cannot get the controls to make it play? This my code so far:
// Get the video
var video = document.getElementById("myVideo");
// Get the button
var btn = document.getElementById("myBtn");
// Pause and play the video, and change the button text
function myFunction() {
if (video.paused) {
video.play();
btn.innerHTML = "Pause";
} else {
video.pause();
btn.innerHTML = "Play";
}
}
.hero #myVideo{
margin-top: 40px;
position: absolute;
z-index: 8000000;
}
.hero img, video{
position: relative;
background-size: cover;
background-position: center;
margin: 0;
height: 1600px;
z
display: flex;
align-items: center;
justify-content: center;
clip-path: polygon(
0 0,
100% 0,
100% 84%,
100% 84%,
50% 100%,
0% 84%,
0 84%
);
}
.layer::after {
content: "";
background: rgba();
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
clip-path: polygon(
0 0,
100% 0,
100% 84%,
100% 84%,
50% 100%,
0% 84%,
0 84%
);
}
.layer > * {
z-index: 10;
}
<div class="hero" >
<div class="fade">
<!--image 1-->
<div class="layer">
<img src="https://fastly.picsum.photos/id/91/3504/2336.jpg?hmac=tK6z7RReLgUlCuf4flDKeg57o6CUAbgklgLsGL0UowU" style = "width:100%;height:800px;">
<div class="hero-text">
<h1 style="font-size:50px">I am John Doe</h1>
<p>And I'm a Photographer</p>
<button>Hire me</button>
</div>
</div>
<!--image 2-->
<div class="layer">
<img src="https://fastly.picsum.photos/id/91/3504/2336.jpg?hmac=tK6z7RReLgUlCuf4flDKeg57o6CUAbgklgLsGL0UowU" style = "width:100%;height:800px;">
<div class="hero-text">
<h1 style="font-size:50px">I am John Doe</h1>
<p>And I'm a Photographer</p>
<button>Hire me</button>
</div>
</div>
<!--image 3-->
<div class="layer" id="myVideo">
<video style = "width:100%;height:800px;" playsinline="playsinline" width="1400" controls="true" height="400" muted="muted" loop="loop">
<source src="https://media.geeksforgeeks.org/wp-content/uploads/20230623105019/Untitled.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</div>
</div>
The video will work if its on autoplay but not on controls? Have a feeling the play/pause needs to be more dominant but adding a z-index to the controls didn't do anything? Any help or tips on how to integrate videos and images in the slick slider would be so greatful.
It seems like you're trying to control the video playback with JavaScript, but there are a couple of issues with your approach. First, you haven't defined an element with the id "myBtn" in your HTML. Second, even if you did, you're not calling the myFunction() function anywhere to control the video playback.
Here's a corrected version of your code:
In this corrected version:
Make sure to call togglePlayPause() where you need it, for example, if you want to play or pause the video on a button click, you can add an event listener to the button.