0

Don't know about cookies much. I just want to my Play\Pause button to remember it's state, nothing more. Here is the code, please help. Thank you

$('.video-control').on('click', function () {
    $(this).toggleClass('video-control_active');
    var currentVideo = document.querySelector('.play');
    if (currentVideo.paused) {
        currentVideo.play();
    } else {
        currentVideo.pause()
    }
})
  • you are not using cookies at all in this snippet. Please read https://stackoverflow.com/questions/1458724/how-do-i-set-unset-a-cookie-with-jquery to get and idea of what you need to save a state as cookie. – Panciz Apr 28 '19 at 15:24

2 Answers2

0

Read cookie when video-playing is the name.

var youCookie = $.cookie('video-playing');  

Create or/and update cookie

$.cookie('video-playing', "true");
$.cookie('video-playing', "false");
Alexander Gorelik
  • 2,544
  • 2
  • 26
  • 50
0

So, I returned to the case and read a bit. This worked for me:

    if(localStorage.paused !== 'true') playlist();
    else {
        videos[currPlayVideo].classList.add('play');
        videos[currPlayVideo].onended = function () {
            playNextVideo();
        };
        $('.video-control').remove('video-control_active');
    };
    $('.video-control').on('click', function () {
        var currentVideo = document.querySelector('.play');
        $(this).toggleClass('video-control_active');
        if (currentVideo.paused) {
            currentVideo.play();
            localStorage.paused = 'false'
        } else {
            currentVideo.pause();
            localStorage.paused = 'true'
        }
    });

and for the Play|pause button to remeber it's state the following:

if (localStorage.getItem("paused") == "true") {
  getFav = localStorage.paused;
  $(".video-control").addClass('video-control_active');
}