开发者

Evaluating java script expression inside function argument

I am trying to define a scale variable (s), where the image scales dynamically according to its value. I don't think the expression s*100 is evaluating as there is no difference in size. What is wrong.

<html>
 <body onload="draw();">
   <canvas id="canvas" width="150" height="150"></canvas>
 </body>
 <script type="application/javascript"> 
    function draw() { 
      var canvas = document.getElementById("canvas");
      if (canvas.getContext) { 
        var ctx = canvas.getContext("2d");            
        var s = 10000;
        ctx.fillStyle = "rgba(0, 0, 200开发者_JAVA技巧, 0.1)";
        ctx.fillRect (0, 0, s*100, s*100);     
      }
    }
  </script>      
</html>


The reason you don't see any change is because you are trying to render a gigantic rectangle onto a 150x150 canvas, so the part outside the canvas is ignored. Make your canvas really big and you'll see it working. Here's a working example, it keeps rendering the same square by increasing the scale each time. http://jsfiddle.net/3ZAex/2/


Figured it out.. it was because my canvas was too small.. width="150" height="150"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜