2016-09-10 1 views
2

この場合、fadeOutが発生する前にどのようにタイムアウトを実行できますか? (コメントがある場所の右)。ファンクションコードの前にsetTimeout

HTML

<button id="button"> Button </button> 

<h1 id="one"> Test</h1> 

CSS

#one {display:none;} 

Javascriptを

$(document).ready(function(){ 
$("#button").click(function(){ 

    $("#one").fadeIn('slow', (function(){ 
/* SetTimoeout */ 
    $("#one").fadeOut('slow'); 

})); 
}) 
}); 

答えて

1

これを試してみてください。

$(document).ready(function(){ 

    $("#button").click(function(){ 

    $("#one").fadeIn('slow', function(){ 

     $("#one").delay(3000).fadeOut('slow'); 

     }) 
    }) 
}) 

決勝コード:

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <style> 
 
     
 
     #one { 
 
      display: none; 
 
     } 
 
     
 
    </style> 
 
</head> 
 
    <body> 
 
     
 
     <button id="button"> Button </button> 
 
     <h1 id="one"> Test</h1> 
 
     
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
     <script> 
 
      
 
    $(document).ready(function(){ 
 

 
     $("#button").click(function(){ 
 

 
     $("#one").fadeIn('slow', function(){ 
 

 
      $("#one").delay(3000).fadeOut('slow'); 
 

 
      }) 
 
     }) 
 
    }) 
 
     
 
     </script> 
 
    </body> 
 
</html>

+0

は、ありがとう、それは両方の方法を働いたが、それは私が求めているものではないのです。私は自分のコメントがある場所をタイムアウトしたいので、フェードインして設定された時間だけ待ってからフェードアウトします。 – Sergi

+0

はい私はそれをdelay()で修正しました。ありがとうございました。 – Sergi

+1

さて、私はそれを更新し、遅延3sを取得します。 – Ehsan