簡體   English   中英

有沒有一種方法可以創建加載屏幕,但要在消失之前設置時間?

[英]Is there a way to create a loading screen but cap the time before it fades away?

我正在嘗試創建一個HTML加載屏幕,隱藏大量圖像,直到至少部分加載它們為止。

以下代碼行當前有效,但是由於圖像的大小,我需要一種方法來限制瀏覽器嘗試預加載所花費的時間。

$(window).load(function(){
    $("#loadingScreen").fadeOut("slow");
    $('#content').fadeIn("slow");
});

為此,我添加了以下內容:

$("#loadingScreen").delay(3000).fadeOut("slow");
$('#content').delay(3000).fadeIn("slow");

我的理由是瀏覽器將首先嘗試加載所有圖像,並且在3秒鍾后,即使圖像沒有完全加載,加載屏幕也會消失。 這樣,當一個人第一次訪問該站點時,他或她將在加載屏幕上花費最多3秒,而在隨后的訪問中,他或她將花費更少的時間,因為圖像將被緩存到其計算機上。

單獨地,兩組代碼都可以工作,但是當我嘗試一起使用它們時,僅運行第二組代碼。 我究竟做錯了什么? 謝謝!

標記:

<body>
    <div id="loadingScreen">
        <img src="img/loadingIcon.gif">
    </div>

    <div id="content" style="display: none">
        <img src="img/image1.jpg">
        <img src="img/image2.jpg">
        <img src="img/image3.jpg">
    </div>
</body>

你有沒有嘗試過:

$("#loadingScreen").delay(3000).fadeOut("slow", function(){
    $('#content').fadeIn("slow");
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM