2012-03-28 7 views
0

ハローのfreindsどのように私はfadein()fadeout()効果 での作業コードをfolowing行うことができますがfadeout()効果を持って行きます。私はループでそれを作ることができますか?その最初の番号がfadein()の後に最後の数字がfadeout()の場合のように。ループフェードイン()やフェードアウト()()

<script>  
var counter = 1; 
    $(function() { 
     incrementCounter(); 
    }); 

    function incrementCounter() { 
     $('#fade').html(counter); 
     counter++; 
     if (counter < 4) { 
     setTimeout(incrementCounter, 2000); 
     } 
    } 
</script> 

答えて

1

ようにあなたは、このようにcounterにチェックを行うことができます:

function incrementCounter() { 
    $('#fade').html(counter); 
    counter++; 
    if(counter%2) 
     $('#fade').fadeOut(); 
    else 
     $('#fade').fadeIn(); 

    if (counter < 4) { 
    setTimeout(incrementCounter, 2000); 
    } 
} 

するか、ターゲットが表示されている場合は、チェックを行うもでき

function incrementCounter() { 
    $('#fade').html(counter); 
    counter++; 
    if($('#fade').is(":visible")) 
     $('#fade').fadeOut(); 
    else 
     $('#fade').fadeIn(); 

    if (counter < 4) { 
    setTimeout(incrementCounter, 2000); 
    } 
} 
関連する問題