Hopscotch example tour设置参数并调用 hopscotch.startTour(tour);
但关闭“x”和“完成”按钮似乎都无法阻止页面加载后再次播放。
如何实现这一点?
最佳答案
您可以在 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 - 使用 Hopscotch 自动播放游览并在关闭/完成后不再播放吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30810516/