[英]Preloader - how to turn it off when returning from the subpage to the main page?
我需要你的預加載器幫助。 我有主站點 (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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.