2016-03-28 28 views
-1

Ben arka plan yavaş yavaş değişiyor şey yapıyorum ama renkler bir uyku komutu olup olmadığını bu yüzden merak sarmak için değiştirmek için web jsWeb js'de bekleme veya uyku komutu var mı?

+1

'setTimeout' ??? –

+1

"Web js" nedir? – j08691

+0

Bu bir [XY Sorun] 'dir (http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Mathletics

cevap

0

bunu değiştirmek isterseniz setInterval kullanabilirsiniz:

var colors = ['red', 'green', 'blue'] 
var count = 0; 


setInterval(function() { 
    document.body.style.backgroundColor = colors[count]; 
    count ++ ; 

    if(count >= colors.length){ 
     count = 0; 
    } 
},1000) 

https://jsfiddle.net/kemiller2002/od5ho3f2/

0

CSS animasyonları gitmek için iyi bir yoldur.

@keyframes example { 
    from {background-color: red;} 
    to {background-color: purple;} 
} 


div { 
    width: 100px; 
    height: 100px; 
    background-color: red; 
    /* Reference her here */ 
    animation-name: example; 
    animation-duration: 4s; 
} 

http://www.w3schools.com/css/css3_animations.asp