我需要你在预加载器方面的帮助。我有主站点 (index.html) 和一个子页面 (subpage.html)。预加载器在访问站点时工作正常,但是,当我从子页面返回主页面时,预加载器再次加载 - 这是问题所在,我不知道如何停止它。我希望预加载器在第一次访问主(索引)页面时只加载一次。我有两个文件:index.html 和 subpage.html。预加载器 div (.box) 在 index.html 中。代码:
<script>
setTimeout(function() {
$('.box').fadeOut('slow', function() {
$(this).remove();
});
}, 3500);
</script>
最佳答案
您可以使用 localStorage ,如果用户第一次或一天访问该站点,则 localStorage
将被设置为已访问,您必须检查用户是否已经访问过,如果没有,则运行 setTimeout
类似的代码,
if(localStorage.getItem('visited')!='1')
setTimeout(function() {
$('.box').fadeOut('slow', function() {
$(this).remove();
localStorage.setItem('visited','1');
});
}, 3500);
}
关于javascript - 预加载器 - 从子页面返回主页面时如何关闭它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54828667/