2016-04-27 92 views
3

當前爲一個網站,我有index.html,about.html等。初始屏幕加載在index.html,但我不希望它在初始加載後再出現主屏幕。 (甚至從約頁面去 - >指數)初始加載後關閉初始屏幕

這是我的jQuery有:

$(document).ready(function() { 
    if ($(".splash").is(":visible")) { 
     $(".wrapper").css({"opacity":"0"}); 
    } 

    $(".splash-arrow").click(function() { 
     $(".splash").slideUp("800", function() { 
      $(".wrapper").delay(100).animate({"opacity":"1.0"}, 800); 
     }); 
    }); 
}); 

它連接到的index.html。有關如何解決這個問題的任何建議?

+0

你寫一個單頁的應用程序,而無需刷新頁面? – Ozrix

+0

@Ozrix不,它不是一個單一的頁面應用 – user3784193

回答

1

如果您想要僅在用戶第一次訪問index.html時才顯示啓動畫面,則需要在某處存儲該信息。通常這是通過LocalStorageCookies完成的。對於後者,github上有一個很好的庫:

js-cookies

請記住,雖然Cookie會隨您發出的每一個請求一起發送回服務器。

示例代碼:

$(document).ready(function() { 
    if (typeof Cookies.get("seen_splash") !== "undefined") { 
     // Insert code to show the splash screen here 
    } 

    // Set the cookie for 365 days. 
    $(".splash-arrow").on("click", function() { 
     Cookies.set("seen_splash", true, { expires: 365 }); 
    }); 
}); 
+0

嗨,我試圖實現js餅乾像你建議和除了當我打印出console.log後設置「seen_splash」爲cookies,它仍然是未定義的。任何想法爲什麼這可能是這種情況? https://jsfiddle.net/r0Ly0s76/ – user3784193

+0

發生這種情況是因爲條件'if(typeof Cookies.get(「seen_splash」)!==「undefined」){...}'檢查cookie是否先前已設置。問題在於你將第1行的cookie設置爲任意字符串值,這意味着cookie現在存在並且存在檢查總是失敗。您只需在用戶看到飛濺時設置cookie,而不是在其他地方。此外,在再次設置cookie之前,不需要刪除cookie,只需覆蓋它就可以覆蓋它 – marvinhagemeister

+0

@ user3784193如果您覺得此帖可以回答您的問題,那麼將您的問題標記爲已接受即可。 – marvinhagemeister