/    Sign up×
Community /Pin to ProfileBookmark

Carousel VideoSlider problem

Hello. My name is Cosmin and I am new on this forum and also I am new in Javascript programming, so I need some help please.
I tried to make a video carousel and I used for this Slick plugin. I wrote the code in Html and CSS and I imported the Javascript file from Slick and I manage to make the carousel working. The content of the carousel is video content not picture. So I put some video inside of the carousel.

The problem started when I want to make a custom controls bar for the video. I manage to make the Javascript code for the Play button and it works but…only when the video is in the first position of a carousel.If I slide the carousel to the next position, the play button doesn’t work and I don’t know why.

Maybe someone can help me please with this problem.
Thank you very much.

Here is the Javascript code:

“`
$(document).ready(function(){
$(‘.caruselPost’).slick({
slidesToShow: 3,
slidesToScroll: 1,
autoplay: false,
autoplaySpeed: 2000,
nextArrow: $(‘.next’),
prevArrow: $(‘.prev’),
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true
}
},
{
breakpoint: 860,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: “unslick”
// instead of a settings object
]
});
});

var video = document.querySelector(‘.video’);
var btn = document.getElementById(‘play-pause’);

function PlayPause() {

if(video.paused){
btn.className = ‘pause’;
video.play();
}else{
btn.className = ‘play’;
video.pause();
}
}

btn.onclick=function(){
PlayPause();
}
“`

to post a comment
JavaScript

65 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumOct 20.2021 — Hi Cosmin and welcome to the forum!
>I manage to make the Javascript code for the Play button and it works but...only when the video is in the first position of a carousel.

This is exactly what `document.querySelector</C> does: It gets the <STRONG>**first**</STRONG> element that matches the selector.<br/>
In order to get the slide currently visible you need to use:
<QUOTE><i>&gt;</i>slickCurrentSlide Returns the current slide index</QUOTE>

However one question pops up: <br/>
At <C>
breakpoint: 1024</C> 3 slides are visible at the same time. Which video should be addressed by the play/pause button then?

BTW: Please use code tags when posting code: <C>
your code here`
or triple backticks. I edited your posting accordingly.
Copy linkTweet thisAlerts:
@CosminBauthorOct 20.2021 — Hello Sempervivum, thank you very much for your answer. I will use the code tags in the future. I didn't know that, thank you.

The carousel plugin that I choose have 3 slides visible at the same time. The total number of slides is 5 but only 3 are visible on the screen at the same time.

I want all the slides to have a video inside them and a controls bar with a play pause button that will work, because I want to place a video in every slide.

For the begining I made only one video with controls and a play pause button and I notice that when the slide that contain this video is in the first position of a carousel, and visible, the play pause button work. But when it slide in the second position and the third position, the play pause button doesn' work.

I try to understand what are you saying about slickCurrentSlide but I don't know where to use it.

I used document.querySelector because I wanted to select the class that contains the video.mp4 itself.

Thank you





Copy linkTweet thisAlerts:
@SempervivumOct 20.2021 — >I made only one video with controls and a play pause button and I notice that when the slide that contain this video is in the first position of a carousel, and visible, the play pause button work. But when it slide in the second position and the third position, the play pause button doesn' work.

OK, apparently I misunderstood what the issue is. I'm gonna set up a test file and check.
Copy linkTweet thisAlerts:
@SempervivumOct 20.2021 — Test file ready, unfortunately it works fine, playing and pausing the video works even when it's out of view. I tested Opera, Chrome, Firefox and Edge. Which browser are you using?

Maybe
  • - your configuration is different from my test setup or

  • - you are using a browser which blocks playing a video when it's not visible.
  • Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — Hello. I use Chrome
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — Then I'm helpless. Do you have this online and can post the URL?

    On which device and OS is Chrome running?
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — I don't want the video to play when it's not visible. I just want the video to play when it's visible in position 1 and also when it's sliding in position 2 and 3. Like I said, the carousel have 3 position visible and also have an autoplay function. I only manage to play the video when it's in position 1. In position 2 and 3 don't want it to play.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — it's not online yet. I have a desktop with windows 10.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — Maybe you can post your test code. Maybe I will find something that I miss. Thank you.
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — @CosminB#1638385 Ah, got it, what you are describing is not an issue but the behavior you desire. I'm gonna look into this ...
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — ... this turned out to be fairly simple as slick slider adds a class "slick-active" to each slide being visible currently.

    Try this javascript for the play/pause function:
    ``<i>
    </i> function PlayPause() {

    if (video.paused) {
    btn.className = 'pause';
    if (video.classList.contains('slick-active')) {
    video.play();
    }
    } else {
    btn.className = 'play';
    video.pause();
    }
    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — Now, it doesn't work at all. Only the instance of the button has change, from play to pause but the video didn't play.
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — I suspect your video resides in a wrapper like this:
    ``<i>
    </i> &lt;div class="caruselPost"&gt;
    &lt;div&gt;
    &lt;video class="video" src="videos/whymelord-360.mp4" controls&gt;&lt;/video&gt;
    &lt;/div&gt;
    &lt;!-- more slides here --&gt;<i>
    </i>
    `</CODE>
    If so, the class is added to the wrapper not to the video and you have to extend the code like this:
    <CODE>
    `<i>
    </i> // initializing slick slider unchanged
    var video = document.querySelector('.video');
    // get the video's wrapper:
    var videoWrapper = video.closest('div');
    var btn = document.getElementById('play-pause');


    function PlayPause() {

    if (video.paused) {
    btn.className = 'pause';
    // check if the video is visible currently:
    if (videoWrapper.classList.contains('slick-active')) {
    video.play();
    }
    } else {
    btn.className = 'play';
    video.pause();
    }
    }

    btn.onclick = function () {
    PlayPause();
    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — My complete test file:
    ``<i>
    </i>&lt;!DOCTYPE html&gt;
    &lt;html&gt;

    &lt;head&gt;
    &lt;title&gt;Video in Slick Slider&lt;/title&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css"
    integrity="sha512-wR4oNhLBHf7smjy0K4oqzdWumd+r5/+6QO/vDda76MW5iug4PT7v86FoEkySIJft3XA0Ae6axhIvHrqwm793Nw=="
    crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;
    &lt;script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"
    integrity="sha512-XtmMtDEcNz2j7ekrtHvOVR4iwwaD6o/FUJe6+Zq+HgcCsk3kj4uSQQR8weQ2QVj1o0Pk6PwYLohm206ZzNfubg=="
    crossorigin="anonymous" referrerpolicy="no-referrer"&gt;&lt;/script&gt;
    &lt;style&gt;
    .caruselPost img,
    .caruselPost video {
    width: 100%;
    height: auto;
    }
    &lt;/style&gt;
    &lt;/head&gt;

    &lt;body&gt;
    &lt;div class="caruselPost"&gt;
    &lt;div&gt;
    &lt;video class="video" src="videos/whymelord-360.mp4" controls&gt;&lt;/video&gt;
    &lt;/div&gt;
    &lt;div&gt;
    &lt;img src="images/bild1.jpg"&gt;
    &lt;/div&gt;
    &lt;div&gt;
    &lt;img src="images/bild2.jpg"&gt;
    &lt;/div&gt;
    &lt;div&gt;
    &lt;img src="images/bild3.jpg"&gt;
    &lt;/div&gt;
    &lt;div&gt;
    &lt;img src="images/bild4.jpg"&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;button id="play-pause"&gt;Play/Pause&lt;/button&gt;
    &lt;button class="prev"&gt;Previous&lt;/button&gt;
    &lt;button class="next"&gt;Next&lt;/button&gt;
    &lt;script type="text/javascript"&gt;
    $(document).ready(function () {
    const slick = $('.caruselPost').slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    autoplay: false,
    autoplaySpeed: 2000,
    nextArrow: $('.next'),
    prevArrow: $('.prev'),
    responsive: [
    {
    breakpoint: 1024,
    settings: {
    slidesToShow: 3,
    slidesToScroll: 3,
    infinite: true,
    dots: true
    }
    },
    {
    breakpoint: 860,
    settings: {
    slidesToShow: 2,
    slidesToScroll: 2
    }
    },
    {
    breakpoint: 480,
    settings: {
    slidesToShow: 1,
    slidesToScroll: 1
    }
    }
    // You can unslick at a given breakpoint now by adding:
    // settings: "unslick"
    // instead of a settings object
    ]
    });
    // callback for "after change"
    // pause video if it's not in view:
    slick.on('afterChange', function (slick, currentSlide) {
    if (!videoWrapper.classList.contains('slick-active')) {
    video.pause();
    btn.className = 'play';
    }

    });
    });


    var video = document.querySelector('.video');
    // get the video's wrapper:
    var videoWrapper = video.closest('div');
    var btn = document.getElementById('play-pause');


    function PlayPause() {

    if (video.paused) {
    btn.className = 'pause';
    // check if the video is visible currently:
    if (videoWrapper.classList.contains('slick-active')) {
    video.play();
    }
    } else {
    btn.className = 'play';
    video.pause();
    }
    }

    btn.onclick = function () {
    PlayPause();
    }
    &lt;/script&gt;

    &lt;/body&gt;

    &lt;/html&gt;<i>
    </i>
    ``

    You may notice that I added another feature: When the video slides out of view, the video is paused.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — It look like this.

    If you want I can send you the the folder with the Html, Css and Javascript file for this carousel.



    &lt;div class="caruselPost"&gt;
    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="Video.mp4" &gt;&lt;/video&gt;
    &lt;div class="controls"&gt;
    &lt;div class="playBtn"&gt;
    &lt;button id="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    <br/>
    <i> </i> &lt;!-- more slides here --&gt;
    <i> </i>
    Copy linkTweet thisAlerts:
    @SempervivumOct 20.2021 — I see. In order to address the correct wrapper you have to add it's class to the selector:

    `var videoWrapper = video.closest('div.post');`

    If you can't get it working then send the files, e. g. in a zip file.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 20.2021 — I will test your code. Thank you.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 21.2021 — Hello. I tested the code but somehow it didn't work. It didn't play in any position.

    Anyhow, I want to put my folder with the files here, but I don't see any option to add files.

    I made the zip arhive.
    Copy linkTweet thisAlerts:
    @SempervivumOct 21.2021 — Do you have webspace already? If so, upload it there.

    Alternatively you might create a fiddle on jsfiddle.net.
    Copy linkTweet thisAlerts:
    @sunmicroOct 22.2021 — Hello
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — I uploaded on jsfiddle at this adress:

    https://jsfiddle.net/CosminBRZ/g0ztL385/2/

    I am interested to make every video to have a play button that works and that I can't manage to do.

    Thank you.
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — >I am interested to make every video to have a play button that works and that I can't manage to do.

    This requires some navigating through the DOM in order to get the video that corresponds to the button having been clicked:

    https://jsfiddle.net/Sempervivum/Lyqpmf2a/1/

    I changed the javascript for the play/pause button to this:
    ``<i>
    </i> // add event listener for click to window:
    window.addEventListener('click', playPause);
    function playPause(event) {
    // event.target is the element having been clicked
    // check if the play/pause button was clicked:
    if (event.target.classList.contains('play-pause')) {
    const
    btn = event.target,
    // get the corresponding video:
    parentCont = btn.closest('div.c-video'),
    video = parentCont.querySelector('video');
    // play or pause video according to current class:
    if (!video.classList.contains('playing')) {
    video.classList.add('playing')
    video.play();
    } else {
    video.classList.remove('playing')
    video.pause();
    }
    }
    }<i>
    </i>
    `</CODE>
    and used a class instead of IDs for the play/pause buttons:<br/>
    <C>
    &lt;button class="play-pause"&gt;&lt;/button&gt;`

    Maybe some additional features will be required: When playing a video, another one currently playing should be first.

    But let's the above get working first.
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — PS: In the jsfiddle I posted above there was still something wrong with the display of the play/pause button. I corrected it here:

    https://jsfiddle.net/Sempervivum/Lyqpmf2a/2/
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — I don't know what to say. Maybe I do something wrong.


    https://jsfiddle.net/CosminBRZ/g0ztL385/3/
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — Please read my latest posting ("PS").
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — I changed allready. Now it seems more likely, I meen now, all the videos are playing like it should, in every position you hit the play button, but it won't pause. After you start playing a video you can not pause it.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — I also attached a play pause class in order to change the instance of the button
    <i>
    </i>// add event listener for click to window:
    window.addEventListener('click', playPause);
    function playPause(event) {
    // event.target is the element having been clicked
    // check if the play/pause button was clicked:
    if (event.target.classList.contains('play-pause')) {
    const
    btn = event.target,
    // get the corresponding video:
    parentCont = btn.closest('div.c-video'),
    video = parentCont.querySelector('video');
    // play or pause video according to current class:
    if (!btn.classList.contains('playing')) {
    btn.classList.add('playing')
    video.play();
    btn.className = 'pause';
    } else {
    btn.classList.remove('playing')
    video.pause();
    btn.className = 'play';
    }
    }
    }


    }
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — One class "playing" being set or not set is sufficient. More will cause confusion only.

    This code works in my test file:
    ``<i>
    </i>&lt;!DOCTYPE html&gt;
    &lt;html&gt;

    &lt;head&gt;
    &lt;title&gt;Video in Slick Slider&lt;/title&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css"
    integrity="sha512-wR4oNhLBHf7smjy0K4oqzdWumd+r5/+6QO/vDda76MW5iug4PT7v86FoEkySIJft3XA0Ae6axhIvHrqwm793Nw=="
    crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;
    &lt;script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"
    integrity="sha512-XtmMtDEcNz2j7ekrtHvOVR4iwwaD6o/FUJe6+Zq+HgcCsk3kj4uSQQR8weQ2QVj1o0Pk6PwYLohm206ZzNfubg=="
    crossorigin="anonymous" referrerpolicy="no-referrer"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css"
    integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA=="
    crossorigin="anonymous" referrerpolicy="no-referrer" /&gt;
    &lt;script src="https://kit.fontawesome.com/064b9e5f27.js" crossorigin="anonymous"&gt;&lt;/script&gt;
    &lt;style&gt;
    * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    }

    .caruselContainer {
    margin-top: 80px;
    background-color: re;
    width: 100%;
    height: auto;
    margin-bottom: 70px;
    }

    .caruselSlider {
    background-color: gree;
    position: relative;
    width: 100%;
    height: auto;
    display: flex;
    }


    .continutLeft {
    background-color: yellow;
    height: auto;
    }

    .continutRight {
    background-color: yellow;
    height: auto;
    }


    .continutLeft .prev {
    font-size: 5rem;
    cursor: pointer;
    height: 100%;
    color: white;
    background-color: rgba(32, 139, 227);
    padding-right: 5px;
    padding-left: 5px;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    }

    .continutRight .next {
    font-size: 5rem;
    cursor: pointer;
    height: 100%;
    color: white;
    background-color: rgba(32, 139, 227);
    padding-right: 5px;
    padding-left: 5px;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;

    }

    .caruselSlider .caruselPost {
    margin-left: 10px;
    margin-right: 10px;
    overflow: hidden;
    background-color: blu;
    display: inline-block;
    }

    .caruselSlider .caruselPost .post {
    height: auto;
    margin-left: 5px;
    margin-right: 5px;
    display: inline-block;
    background-color: cyan;
    }





    .video {
    width: 100%;
    }



    .c-video {

    height: auto;

    background-color: yello;
    position: relative;

    }

    .controls {
    display: flex;
    position: absolute;
    bottom: 0px;
    width: 100%;
    flex-wrap: wrap;
    height: 40px;
    background: re;
    }


    .playBtn {
    background-color: rgba(32, 139, 227);
    width: 7.5%;
    height: 100%;
    margin-left: 20px;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    }

    .playBtn button {

    background: none;
    border: 0px;
    outline: 0px;
    cursor: pointer;



    }

    .playBtn button::before {
    content: "f04b";
    font-weight: 900;
    display: inline-block;
    font-family: "Font Awesome 5 Free";
    font-style: normal;
    font-size: 2vw;
    font-variant: normal;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    color: white;
    }

    .playBtn button.playing::before {
    content: "f04c";
    }
    &lt;/style&gt;
    &lt;/head&gt;

    &lt;body&gt;
    &lt;div class="caruselContainer"&gt;
    &lt;div class="caruselSlider"&gt;

    &lt;div class="continutLeft"&gt;
    &lt;i class="fas fa-chevron-left prev"&gt;&lt;/i&gt;
    &lt;/div&gt;


    &lt;div class="caruselPost"&gt;
    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="../videos/test.mp4"&gt;&lt;/video&gt;
    &lt;div class="controls"&gt;
    &lt;div class="playBtn"&gt;
    &lt;button class="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;



    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="../videos/test2.mp4"&gt;&lt;/video&gt;
    &lt;div class="controls"&gt;

    &lt;div class="playBtn"&gt;
    &lt;button class="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;




    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="Video2.mp4"&gt;&lt;/video&gt;
    &lt;div class="controls"&gt;

    &lt;div class="playBtn"&gt;
    &lt;button class="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;

    &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="Video3.mp4"&gt;&lt;/video&gt;
    &lt;div class="controls"&gt;

    &lt;div class="playBtn"&gt;
    &lt;button class="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;

    &lt;/div&gt;
    &lt;/div&gt;




    &lt;div class="post"&gt;
    &lt;div class="c-video"&gt;
    &lt;video class="video" src="Video4.mp4"&gt;&lt;/video&gt;
    &lt;div class="controls"&gt;

    &lt;div class="playBtn"&gt;
    &lt;button class="play-pause"&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;/div&gt;

    &lt;/div&gt;
    &lt;/div&gt;



    &lt;/div&gt;


    &lt;div class="continutRight"&gt;
    &lt;i class="fas fa-chevron-right next"&gt;&lt;/i&gt;&lt;/i&gt;
    &lt;/div&gt;


    &lt;/div&gt;
    &lt;/div&gt;
    &lt;script&gt;
    $('.caruselPost').slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    autoplay: false,
    autoplaySpeed: 2000,
    nextArrow: $('.next'),
    prevArrow: $('.prev'),
    responsive: [
    {
    breakpoint: 1024,
    settings: {
    slidesToShow: 3,
    slidesToScroll: 3,
    infinite: true,
    dots: true
    }
    },
    {
    breakpoint: 1024,
    settings: {
    slidesToShow: 2,
    slidesToScroll: 2
    }
    },
    {
    breakpoint: 480,
    settings: {
    slidesToShow: 1,
    slidesToScroll: 1
    }
    }
    // You can unslick at a given breakpoint now by adding:
    // settings: "unslick"
    // instead of a settings object
    ]
    });

    // add event listener for click to window:
    window.addEventListener('click', playPause);
    function playPause(event) {
    // event.target is the element having been clicked
    // check if the play/pause button was clicked:
    if (event.target.classList.contains('play-pause')) {
    const
    btn = event.target,
    // get the corresponding video:
    parentCont = btn.closest('div.c-video'),
    video = parentCont.querySelector('video');
    // play or pause video according to current class:
    if (!btn.classList.contains('playing')) {
    btn.classList.add('playing')
    video.play();
    } else {
    btn.classList.remove('playing')
    video.pause();
    }
    }
    }
    &lt;/script&gt;

    &lt;/body&gt;

    &lt;/html&gt;<i>
    </i>
    ``

    Unfortunately I have no video I have copyright on and can post it, therefore I was not able to make the fiddle work completely.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — A,ok, I understand now that you remove my play and pause class from Css and replace with playing class. I didn't saw that that's why I put the btn class in the code.

    Indeed now it's working. Thank you very much, You are very kind. All I need to do now is to understand your code in order for me to learn something from this.

    Thank you very much again.
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — You're welcome!

    What about this remark?
    >Maybe some additional features will be required: When playing a video, another one currently playing should be paused first.

    Currently the user can play one more video without pausing the first one. Thus both videos will play at the same time.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — Yes, I notice that, but frankly I didn't manage to solve this problem with play button.

    I figure that it can be solve with something like: if one video playing, video.pause the rest of the video, but I can't figure how to make the distinction between them.
    Copy linkTweet thisAlerts:
    @SempervivumOct 22.2021 — Yes, I will post a solution tomorrow.
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 22.2021 — Many thanks!
    Copy linkTweet thisAlerts:
    @SempervivumOct 23.2021 — It can be done by a slight modification in the function playPause:
    ``<i>
    </i> function playPause(event) {
    // event.target is the element having been clicked
    // check if the play/pause button was clicked:
    if (event.target.classList.contains('play-pause')) {
    const
    btn = event.target,
    // get the corresponding video:
    parentCont = btn.closest('div.c-video'),
    video = parentCont.querySelector('video');
    // play or pause video according to current class:
    if (!btn.classList.contains('playing')) {

    // first pause another video playing already
    // the button of that video has the class "playing":
    btnPlaying = document.querySelector('button.play-pause.playing');
    // if such button exists, pause the video by simulating a click:
    if (btnPlaying) {
    btnPlaying.click();
    }

    btn.classList.add('playing')
    video.play();
    } else {
    btn.classList.remove('playing')
    video.pause();
    }
    }
    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @CosminBauthorOct 23.2021 — Thank you very much. I appreciate your effort. I understand 80% what you did in the code but I need to to dig deeper into that and for this I want to make a sound button and a progress bar on my own based on what I learned from you, in order to see if I manage to do that. I will post here my progress and if I manage to do that. After that I will want your opinion if you want.

    Thank you very much again.
    Copy linkTweet thisAlerts:
    @SempervivumOct 23.2021 — You're very welcome, feel free to ask for my or other's opinion when you are finished. Or ask when you are stuck.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 15.2021 — Hello Sempervivum.

    Sorry for my late update. For several days I tryed to implement another play button on the center of the screen, but I off course I didn't succeed. The second button I want to have this following function. When you see the video for the first time the is on pause and the central button is on screen. When you click it, the video start, the button disapear and the bottom controls bar will be active.

    I manage to make the code for one single video but like the previous problem I didn't manage to do it for all the video on the carousel.

    The code for the single video I uploaded at this address just for example.

    https://jsfiddle.net/CosminBRZ/hwfke23t/1/


    And here is the previous code that I tryed to modify by implementing a central play button and I don't succeed.

    Somehow I feel that the button that I want to implement is not part of the event and that's why it didn't work.

    https://jsfiddle.net/CosminBRZ/hwfke23t/3/

    Thank you

    Cosmin
    Copy linkTweet thisAlerts:
    @SempervivumNov 16.2021 — Unfortunately the HTML is missing in your second fiddle.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 16.2021 — Hello. Nice to hear you. I uploaded again the whole project.

    https://jsfiddle.net/CosminBRZ/nae0qdbk/
    Copy linkTweet thisAlerts:
    @SempervivumNov 16.2021 — There are no videos, therefore I assume that the current issue is related to the layout. At the first glace it looks fine. Is the issue the following?
    > the central button is on screen. When you click it, the video start, the button disapear and the bottom controls bar will be active.

    The central button is always visible instead of disappearing when clicked and the bottom controls are active from the beginning instead of appearing when the central button is clicke.
    Copy linkTweet thisAlerts:
    @SempervivumNov 16.2021 — Done:

    https://jsfiddle.net/Sempervivum/14dbmaxz/
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 16.2021 — Ok. Thank you very much man. Now I understand what you did in the code and I want to try something similar and tomorrow I want to ask you some question, if you please, about this code in order for me to understand much better the logic of this, because I don't want to bother you every time I want to make some modification.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 17.2021 — Hello. I study the code and I understand that you made for the same event( which is click) 2 different if statements. One for the central button and one for the bottom button.

    So, if I want to add other features like, progress bar or sound button, or full screen button, the way to do this is to add it inside this function. I mean the event function. And to asign the DOM elements related to the parentContainer( c-video).

    Otherwise the event will not know who to assign the elements. Is that right?
    Copy linkTweet thisAlerts:
    @SempervivumNov 17.2021 — >you made for the same event( which is click) 2 different if statements

    Yes, the reason is that there are two play buttons being located on different position is the DOM. Accordingly the procedure to find the video is different. And additionally, apart from playing the video, the actions being taken are differen.

    > if I want to add other features like, progress bar or sound button, or full screen button, the way to do this is to add it inside this function. I mean the event function. And to asign the DOM elements related to the parentContainer( c-video).

    Otherwise the event will not know who to assign the elements.


    Yes, you should place additional actions in the same function playPause (although that name might not match the function afterwards). Presumed the element you intend to access is located in the same container it should be possible to access it. It would be easiest if all the elements involved would be located inside the container .c-video.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 17.2021 — Yes, all the elements are located inside the c-video container. For example.

    If I want to use a full screen button I will need to make another if statement with the full screen button be the event target and assign to it the parent c-video. And the function will receive the event argument from the full screen button. Something like that?
    Copy linkTweet thisAlerts:
    @SempervivumNov 17.2021 — Yes, when you add a full screen button you will have to find the video:
  • - event.target is the button having been clicked

  • - search upwards in the DOM by use of the function closest in order to find the parent c-video

  • - the search downwards by use of the function document.querySelector


  • But note: When using events fired by the video they will not bubble up, thus you will have to add the event listener directly at the video.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 17.2021 — Ok. I will try first with the full screen button
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 17.2021 — First off all I modified the code that the controls bar to stay static when the video is on pause. I added a class .static and put it in the code. Still the controls bar continue to translate .

    https://jsfiddle.net/CosminBRZ/59cp7yho/2/
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 17.2021 — I find the mistake. I forgot to add in HTML .static class. Now it's stay still when video is on pause but other strange thing happen. If I want to remove this class when the video it is playing again, if I add this fragment of code <code>else {

    video.play();
    controls.classList.remove(.'static');

    } </code>


    the whole position of the document it's changing and nothing works.



    https://jsfiddle.net/CosminBRZ/59cp7yho/4/
    Copy linkTweet thisAlerts:
    @SempervivumNov 17.2021 — No dot is required when manipulating classes by use of classList:
    ``<i>
    </i>controls.classList.remove('static');<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 18.2021 — Yes, I notice minutes later after I post it, that it was a dot mistake. Thank you.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 23.2021 — Hello. I manage to make the code for the fullscreen button. I put another if statement in the general function and it looks like this:

    <code>if (event.target.classList.contains('fullSCBtn')){

    const
    screenBtn = event.target,
    parentCont = screenBtn.closest('div.c-video'),
    video = parentCont.querySelector('video');

    if (!screenBtn.classList.contains('compress')){
    video.requestFullscreen();
    }

    }

    </code>

    And it works. The only problem is when it is in the fullscreen mode, the control bar have the default appearance. I think this is because of the video.requestFullscreen embeded method.

    Maybe I should do something like this: document.requestFullscreen and assign the video div to make fullscreen, and maybe in this case it will show my control bar not the default one.
    Copy linkTweet thisAlerts:
    @SempervivumNov 23.2021 — Unfortunately you used angle brackets instead of square bracket for formatting your code. This would be correct:

    `your code here`
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 23.2021 — oh, ok.
    if (event.target.classList.contains('fullSCBtn')){

    <i> </i> const
    <i> </i> screenBtn = event.target,
    <i> </i> parentCont = screenBtn.closest('div.c-video'),
    <i> </i> video = parentCont.querySelector('video');
    <i> </i>
    <i> </i> if (!screenBtn.classList.contains('compress')){
    <i> </i> video.requestFullscreen();
    <i> </i> }
    Copy linkTweet thisAlerts:
    @SempervivumNov 24.2021 — Regarding your original question: Making the container full screen seems to be a good idea. Take a look at this discussion:

    https://stackoverflow.com/questions/7130397/how-do-i-make-a-div-full-screen
    Copy linkTweet thisAlerts:
    @hupNov 24.2021 — we always try to know about such new things for <a href="https://astroindusoot.com/">astrology</a> which can benefit us and our country very well.

    but the problem comes here that after all, when we think of doing something new, then do not have money
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 24.2021 — Thank you.
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 26.2021 — I manage to do the fullscreen button.

    Here is the entire code:

    https://jsfiddle.net/CosminBRZ/4azt1qwL/1/

    Still, I think I have some small mistake. When I push the fullscreen button and it enter the fullscreen mode, the icon of the button it change like it should, the same when I push the button back and exit the full screen mode. But if I want to exit the fullscreen mode by pressing the ESC key, the icon of the fullscreen button remains unchanged, what I mean, it is not toggle the class.

    Also, in fullscreen mode, the controls bar does not make the translate movement. Maybe because the mouse pointer not leave the DIV that trigger the movement? Maybe I need to implement a function like settimeout? after a couple a second to trigger the translate movement?
    Copy linkTweet thisAlerts:
    @SempervivumNov 26.2021 — >But if I want to exit the fullscreen mode by pressing the ESC key, the icon of the fullscreen button remains unchanged, what I mean, it is not toggle the class.

    You can easily detect pressing the escape button and modify your class:

    https://stackoverflow.com/questions/3369593/how-to-detect-escape-key-press-with-pure-js-or-jquery
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 27.2021 — Ok, but it's not only the ESC button that exit, it's also a X sign that you can press it and exit the fullscreen. I wonder if the following approach would be succesfull: When the video it's not in fullscreen mode, the icon on the button is......(what icon I choose).

    Something like <i>
    </i>if(!(here to put the condition that the DIV is not in fullscreen)){
    screenBtn.classList.remove('compress');
    }

    Copy linkTweet thisAlerts:
    @CosminBauthorNov 27.2021 — I tryed this but no succes:
    <i>
    </i>
    if (event.target.classList.contains('fullSCBtn')){

    <i> </i> const
    <i> </i> screenBtn = event.target,
    <i> </i> parentCont = screenBtn.closest('div.c-video');
    <i> </i>
    <i> </i>
    <i> </i> if (!screenBtn.classList.contains('compress')){

    <i> </i> if(!document.fullscreenElement){
    <i> </i> screenBtn.classList.remove('compress');
    <i> </i> }

    <i> </i> parentCont.requestFullscreen();

    <i> </i> }else{
    <i> </i> document.exitFullscreen();
    <i> </i> }
    <i> </i> screenBtn.classList.toggle('compress');
    <i> </i> }
    Copy linkTweet thisAlerts:
    @SempervivumNov 28.2021 — It seems to me that your code should read like this:
    ``<i>
    </i> if (event.target.classList.contains('fullSCBtn')) {
    const
    screenBtn = event.target,
    parentCont = screenBtn.closest('div.c-video');
    // is the video not in fullscreen mode?
    if (!document.fullscreenElement) {
    // request full screen for the parent container:
    parentCont.requestFullscreen();
    // toolbar should be visible now,
    // remove class "compressed":
    screenBtn.classList.remove('compress');
    } else {
    // video is in fullscreen mode,
    // exit this mode:
    document.exitFullscreen();
    }
    }<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @instagramlikesNov 28.2021 — Cosmin Adrian Bejan, PhD, is an Assistant Professor of Biomedical Informatics in the School of Medicine at Vanderbilt University.

    [instagramlikes singapore](https://buyinstasingapore.com/)
    Copy linkTweet thisAlerts:
    @CosminBauthorNov 28.2021 — In that case, the class of the button didn't change.

    The original code was like this:
    <i>
    </i>if (event.target.classList.contains('fullSCBtn')) {
    const
    screenBtn = event.target,
    parentCont = screenBtn.closest('div.c-video');
    // is the video not in fullscreen mode?
    if (!document.fullscreenElement) {
    // request full screen for the parent container:
    parentCont.requestFullscreen();
    // toolbar should be visible now,
    // remove class "compressed":
    <br/>
    <i> </i> } else {
    <i> </i> // video is in fullscreen mode,
    <i> </i> // exit this mode:
    <i> </i> document.exitFullscreen();
    <i> </i>
    <i> </i> }
    <i> </i> screenBtn.classList.toggle('compress');
    <i> </i> }
    <i> </i>


    All works but when I exit by pressing ESC or by clicking the X icon on the top of the fullscreen mode, the class of the button didn't change.

    That's why I tryed the previous code.



    Copy linkTweet thisAlerts:
    @instagramNov 29.2021 — This is a beautiful responsive video carousel slider with responsive lightbox for WordPress blogs and sites. Admin can manage any number of videos into the ...

    [instagram followers singapore](https://buyinstasingapore.com/)
    ×

    Success!

    Help @CosminB spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...