2016-02-04 46 views
0

我想淡出一個div,然後淡入另一個div,這對我有用,問題是我不能延遲它,所以第一個div不推其他分區下來...jQuery .fadeOut然後等待,然後.fadeIn不起作用

這是我的HTML(一切都是內聯):

<!doctype html> 
 
<html> 
 
    <head> 
 
     <title>JavaScript popup</title> 
 
     <meta charset="utf-8"> 
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
 
     <script src="main.js" type="text/javascript"></script> 
 
    </head> 
 
    <script type="text/javascript"> 
 
     $(document).ready(function(){ 
 
      $(".main").hide(); 
 
     }); 
 
     $("#continue-button").click(function(){ 
 
      $(".vge-eksponering").hide(); 
 
      $(".main").show();  
 
     });   
 
    </script> 
 
    
 
    <body style="background-color:lightgrey;"> 
 
     <div class="vge-eksponering" style="text-align:center;"> 
 
      <h1>Tjek VGEs hjemmeside ud på: 
 
      <br> 
 
      <a href="http://www.vge.dk" target="_blank">www.vge.dk</a></h1> 
 
      <button id="continue-button" style="font-size:2em;">Fortsæt til VGE News</button> 
 
     </div> 
 
     <script> 
 
      $("#continue-button").click(function(){ 
 
       $(".vge-eksponering").fadeOut(1200); 
 
       $(".main").fadeIn(1200); 
 
      }); 
 
     </script> 
 
     <div class="main" style="background-color:lightblue;"> 
 
      <h1>JavaScript popup</h1> 
 
      <p>Hopefully this will work soon...</p> 
 
     </div> 
 
    </body> 
 
</html>

編輯:我用這個,和它的工作。

$(".vge-eksponering").fadeOut(1200); 
$(".main").delay(1200).fadeIn(1200); 
+0

你想淡出'.vge-eksponering'並且,當它完成淡出,在'.main'褪色? –

回答

4

你有(至少)兩個選擇:

如果只有一個.vge-eksponering元素,然後使用完成回調fadeOut爲您提供:

$(".vge-eksponering").fadeOut(1200, function() { 
    $(".main").fadeIn(1200); 
}); 

或者只是使用delay與價值相當於第一個fadeOut:

$(".vge-eksponering").fadeOut(1200); 
$(".main").delay(1200).fadeIn(1200); 
+1

它的工作,謝謝。我使用了.delay函數。 –