Hopscotch example tour设置参数并调用hopscotch.startTour(tour);,但是关闭“ x”或“ Done”按钮似乎都无法阻止页面加载后再次播放。

如何做到这一点?

最佳答案

您可以在onend函数上使用localstorage / cookie。

function setCookie(key, value) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
    document.cookie = key + '=' + value + ';path=/' + ';expires=' + expires.toUTCString();
};

function getCookie(key) {
    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    return keyValue ? keyValue[2] : null;
};

var tour = {
    onEnd: function() {
        setCookie("toured", "toured");
    },
    onClose: function() {
        setCookie("toured", "toured");
    }
};

// Initialize tour if it's the user's first time
if (!getCookie("toured")) {
    hopscotch.startTour(tour);
}

关于javascript - 使用跳房子自动播放游览,并且在关闭/完成后再也不会播放吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30810516/

10-09 08:00