javascript - how to change color of rectangle every 5 seconds in js -


this code change color of rectangle fast. how can change color change every 5 seconds?

var bgcolorlist=new array("#dfdfff", "#ffffbf", "#80ff80", "#eaeaff", "#c9ffa8", "#f7f7f7", "#ffffff", "#dddd00") pop.draw.rect(0, 0, pop.width, pop.height, bgcolorlist[math.floor(math.random()*bgcolorlist.length)]); 

please try   var bgcolorlist=new array("#dfdfff", "#ffffbf", "#80ff80", "#eaeaff","#c9ffa8", "#f7f7f7", "#ffffff",     "#dddd00") function draw(){ var canvas = document.getelementbyid('a'); var context = canvas.getcontext('2d'); context.beginpath(); context.rect(20,20, 100, 100); context.fillstyle =bgcolorlist[math.floor(math.random()*bgcolorlist.length)]; context.fill(); context.linewidth = 7; } draw(); setinterval(function(){ draw(); },5000); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -