2016-03-28 2 views
-1

Ich mache etwas, wo der Hintergrund langsam ändert, aber die Farben ändern Ich habe mich gefragt, um schnell so, wenn es einen Schlafbefehl von Web-js warGibt es in web js einen Warte- oder Schlafbefehl?

+1

'setTimeout' ??? –

+1

Was ist "web js"? – j08691

+0

Dies ist ein [XY Problem] (http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Mathletics

Antwort

0

Sie können setInterval verwenden, wenn Sie es ändern wollen:

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-Animationen sind ein guter Weg zu gehen.

@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

Verwandte Themen