English 中文(简体)
Canvas和globalCompositeOperations
原标题:Canvas and globalCompositeOperations

嘿,我有下面的代码,它给你一个“面具”的效果。

JSFiddle:http://jsfiddle.net/neuroflux/m5Fj2/7/

Basically, I would like a semi-opaque gradient instead of a circle... I tried to put the following code in, but to no advail.

grad = ctx.createRadialGradient(0,0,0,0,0,600); 
  grad.addColorStop(0,  #000 );
  grad.addColorStop(1,  rgb(  + color +  ,   + color +  ,   + color +  ) );

  // assign gradients to fill
  ctx.fillStyle = grad;

  // draw 600x600 fill
  ctx.fillRect(0,0,600,600);

但我无法让它发挥作用:(

救命。

最佳回答

首先,

        tmpCanvas = document.createElement( canvas );
        tmpCanvas.width = c.width;
        tmpCanvas.height = c.height;

        tmpCtx = tmpCanvas.getContext( 2d );

是那种你永远不想在循环中做的事情。现在,您每40毫秒创建一个新画布!太疯狂了!

其次,如果你想要一个半透明的渐变,为什么不使用globalCompositeOperations,只使用半透明的颜色呢?

将alpha添加到颜色中,如下所示:

 // half transparent
grad.addColorStop(0,  rgba(0,0,0,.5) );
grad.addColorStop(1,  rgba(  + color +  ,   + color +  ,   + color +  0.5) );
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签