将Cookie添加到jQuery切换视频BG切换器

时间:2019-04-28 14:50:46

标签: jquery cookies html5-video toggle

不太了解Cookie。我只想让我的播放\暂停按钮记住它的状态,仅此而已。这是代码,请帮助。 谢谢

$('.video-control').on('click', function () {
    $(this).toggleClass('video-control_active');
    var currentVideo = document.querySelector('.play');
    if (currentVideo.paused) {
        currentVideo.play();
    } else {
        currentVideo.pause()
    }
})

2 个答案:

答案 0 :(得分:0)

视频播放为名称读取cookie。

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

创建或/和更新cookie

$.cookie('video-playing', "true");
$.cookie('video-playing', "false");

答案 1 :(得分:0)

所以,我回到案子并读了一点。这对我有用:

    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'
        }
    });

,并且要让“播放|暂停”按钮记住以下内容:

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