2015-04-22 41 views
1

我一直在嘗試用jQuery淡出CSS3預加載器。我一直試圖停止動畫(這是一個旋轉的盒子),然後淡入盒子裏面的一封信,然後讓它們都淡出,信件比盒子晚一點。我遇到了這樣的問題,即信件在比我想要的時間晚的地方消失,並且如果淡出的速度非常快,則會出現這種情況。下面是代碼:jQuery的延遲淡入時間比預期的要長

\t //<![CDATA[ 
 
$(window).load(function() { // makes sure the whole site is loaded 
 
$('.loader-inner').css({'-webkit-animation': 'none'}); 
 
$('.loader').delay(100).css({'-webkit-animation': 'none'}); // will first fade out the loading animation 
 
$('.letter').delay(100).fadeIn('slow'); 
 
$('.preloader').delay(2050).fadeOut('slow');// will fade out the white DIV that covers the website. 
 
$('.letter').delay(2060).fadeOut(900); 
 
$('body').delay(2060).css({'overflow':'visible'}); 
 
\t \t }); 
 
\t //]]>
body, html { 
 
    height: 100%; 
 
    text-align: center; 
 
} 
 

 
body { 
 
    background-color: #2f2f2f; 
 
    } 
 
.preloader { 
 
position: fixed; 
 
    
 

 
top: 0; 
 
left: 0; 
 
right: 0; 
 
bottom: 0; 
 
z-index: 99999; 
 
background-color: #2f2f2f; 
 
} 
 

 
.loader { 
 
    display: block; 
 
    width: 60px; 
 
    height: 60px; 
 
    position: fixed; 
 
    border: 5px solid #d5b317; 
 
    top: 50%; 
 
    left:50%; 
 
    -webkit-animation: loader 2s infinite ease; 
 
    z-index: -10; 
 
    overflow: hidden; 
 
    margin-left: -29px 
 
} 
 

 
.loader-inner { 
 
    vertical-align: top; 
 
    display: inline-block; 
 
    width: 100%; 
 
    background-color: #d5b317; 
 
    -webkit-animation: loader-inner 2s infinite ease-in; 
 
    z-index: -10; 
 
} 
 
@font-face { 
 
    font-family: 'Adobe Gurmukhi'; 
 
    src: url(/fonts/AdobeGurmukhi-Regular.ttf); 
 
} 
 

 
.letter { 
 
display:hidden; 
 
color: #f7d11e; 
 
font-family: 'Adobe Gurmukhi'; 
 
font-size: 70px; 
 
position:absolute; 
 
top: 50%; 
 
left: 50%; 
 
margin-top: -17px; 
 
margin-left: -19px; 
 
z-index: -9; 
 

 
} 
 
@-webkit-keyframes loader { 
 
    0% { 
 
    transform: rotate(0deg); 
 
    } 
 
    
 
    25% { 
 
    transform: rotate(180deg); 
 
    } 
 
    
 
    50% { 
 
    transform: rotate(180deg); 
 
    } 
 
    
 
    75% { 
 
    transform: rotate(360deg); 
 
    } 
 
    
 
    100% { 
 
    transform: rotate(360deg); 
 
    } 
 
} 
 

 
@-webkit-keyframes loader-inner { 
 
    0% { 
 
    height: 0%; 
 
    } 
 
    
 
    25% { 
 
    height: 0%; 
 
    } 
 
    
 
    50% { 
 
    height: 100%; 
 
    } 
 
    
 
    75% { 
 
    height: 100%; 
 
    } 
 
    
 
    100% { 
 
    height: 0%; 
 
    } 
 
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"> 
 
     </script> 
 
<!--preloader--> 
 
<div class="preloader"> 
 
    <span class="loader"><span class="loader-inner"></span></span> 
 
    </div> 
 
    <span><p class="letter">ਅ</p></span>

回答

1

.preloader(99999)的Z指數高於.letter(-9)的Z指數。您遇到的延遲是延遲到.preloader淡出並因此揭示.letter。作爲一個快速解決方案,我使得012-的Z指數高於.preloader,並且延遲消失了。

\t //<![CDATA[ 
 
$(window).load(function() { // makes sure the whole site is loaded 
 
$('.loader-inner').css({'-webkit-animation': 'none'}); 
 
$('.loader').delay(100).css({'-webkit-animation': 'none'}); // will first fade out the loading animation 
 
$('.letter').delay(100).fadeIn('slow'); 
 
$('.preloader').delay(2050).fadeOut('slow');// will fade out the white DIV that covers the website. 
 
$('.letter').delay(2060).fadeOut(900); 
 
$('body').delay(2060).css({'overflow':'visible'}); 
 
\t \t }); 
 
\t //]]>
body, html { 
 
    height: 100%; 
 
    text-align: center; 
 
} 
 

 
body { 
 
    background-color: #2f2f2f; 
 
    } 
 
.preloader { 
 
position: fixed; 
 
    
 

 
top: 0; 
 
left: 0; 
 
right: 0; 
 
bottom: 0; 
 
z-index: 99999; 
 
background-color: #2f2f2f; 
 
} 
 

 
.loader { 
 
    display: block; 
 
    width: 60px; 
 
    height: 60px; 
 
    position: fixed; 
 
    border: 5px solid #d5b317; 
 
    top: 50%; 
 
    left:50%; 
 
    -webkit-animation: loader 2s infinite ease; 
 
    z-index: -10; 
 
    overflow: hidden; 
 
    margin-left: -29px 
 
} 
 

 
.loader-inner { 
 
    vertical-align: top; 
 
    display: inline-block; 
 
    width: 100%; 
 
    background-color: #d5b317; 
 
    -webkit-animation: loader-inner 2s infinite ease-in; 
 
    z-index: -10; 
 
} 
 
@font-face { 
 
    font-family: 'Adobe Gurmukhi'; 
 
    src: url(/fonts/AdobeGurmukhi-Regular.ttf); 
 
} 
 

 
.letter { 
 
display:hidden; 
 
color: #f7d11e; 
 
font-family: 'Adobe Gurmukhi'; 
 
font-size: 70px; 
 
position:absolute; 
 
top: 50%; 
 
left: 50%; 
 
margin-top: -17px; 
 
margin-left: -19px; 
 
z-index: 999999; 
 

 
} 
 
@-webkit-keyframes loader { 
 
    0% { 
 
    transform: rotate(0deg); 
 
    } 
 
    
 
    25% { 
 
    transform: rotate(180deg); 
 
    } 
 
    
 
    50% { 
 
    transform: rotate(180deg); 
 
    } 
 
    
 
    75% { 
 
    transform: rotate(360deg); 
 
    } 
 
    
 
    100% { 
 
    transform: rotate(360deg); 
 
    } 
 
} 
 

 
@-webkit-keyframes loader-inner { 
 
    0% { 
 
    height: 0%; 
 
    } 
 
    
 
    25% { 
 
    height: 0%; 
 
    } 
 
    
 
    50% { 
 
    height: 100%; 
 
    } 
 
    
 
    75% { 
 
    height: 100%; 
 
    } 
 
    
 
    100% { 
 
    height: 0%; 
 
    } 
 
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"> 
 
     </script> 
 
<!--preloader--> 
 
<div class="preloader"> 
 
    <span class="loader"><span class="loader-inner"></span></span> 
 
    </div> 
 
    <span><p class="letter">ਅ</p></span>

0

你在做什麼,首先你使用的延遲,這意味着你需要一些延遲後打電話到淡出,你給出的延遲時間2秒,其正常工作的預期。

它在2秒後開始消失。

我認爲它的工作和預期的一樣,如果你想很快淡出它,那麼你必須減少延遲時間,以消除延遲。

希望這可以幫助你。 謝謝!

0

你可以嘗試回調函數

$('.letter').delay(100).fadeIn('slow', function(){ 
    // function called after fade in finished 
    setTimeout(function(){ 
      $('.preloader').fadeOut('slow'); 
      $('.letter').fadeOut(900); 
      $('body').css({'overflow':'visible'}); 
     }, 2600); 
    }); 
0

本替換你的代碼,兩者都將淡出在同一時間。

// will fade out the white DIV that covers the website. 
    $('.letter').delay(2060).fadeOut('fast');