canvas fill color, stays black -


i have code draw triangular canvas. can't manage fill color other black. it's stated work ctx.fillstyle doesn't. must missing in code can guys have look?

  function drawshape(){     // canvas element using dom       var canvas = document.getelementbyid('balkboven');      // make sure don't execute when canvas isn't supported        if (canvas.getcontext){      // use getcontext use canvas drawing        var ctx = canvas.getcontext('2d');        var ctxwidth = window.innerwidth;                   // filled triangle        ctx.canvas.width  = window.innerwidth;        ctx.beginpath();        ctx.moveto(0,0);        ctx.lineto(ctxwidth,0);        ctx.lineto(0,105);        ctx.fill();        ctx.fillstyle="red"       } } 

fillstyle , strokestyle have set before draw object, not afterwards!

think of loading paint onto paintbrush. must before stroke brush!

see: http://jsfiddle.net/f8smr/


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -