【问题标题】:Adding cookies to jquery toggle video-bg switcher将 cookie 添加到 jquery 切换视频-bg 切换器
【发布时间】:2019-09-17 08:59:58
【问题描述】:

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

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

【问题讨论】:

标签: jquery cookies html5-video toggle


【解决方案1】:

video-playing 为名称时读取 cookie。

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

创建或/和更新 cookie

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

【讨论】:

    【解决方案2】:

    所以,我回到案例并阅读了一下。这对我有用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 1970-01-01
      相关资源
      最近更新 更多