最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding mask layer over fabric.js canvas - Stack Overflow

programmeradmin0浏览0评论

I have a problem that I'd like to add round mask on top of the editable fabric.js HTML5 canvas. Similar problem is described in this article:

Creating an Image Mask with HTML 5 Canvas

My problem is that when I add this layer on top of the fabric.js canvas then my canvas is not editable any more inside this transparent circle. This means that the top element (the mask) captures the click/drag event, but I'd like to move the items under this mask element. Looking for ideas, how to work around this problem.

I have a problem that I'd like to add round mask on top of the editable fabric.js HTML5 canvas. Similar problem is described in this article:

Creating an Image Mask with HTML 5 Canvas

My problem is that when I add this layer on top of the fabric.js canvas then my canvas is not editable any more inside this transparent circle. This means that the top element (the mask) captures the click/drag event, but I'd like to move the items under this mask element. Looking for ideas, how to work around this problem.

Share Improve this question asked Nov 27, 2011 at 22:15 ainlaainla 5299 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You can utilize built-in support for masks in fabric.

Here's an example of creating a circular mask at 100/100 with the radius of 200:

var canvas = new fabric.Canvas('...');
// ...
canvas.clipTo = function (ctx) {
  ctx.arc(100, 100, 200, 0, Math.PI*2, true);
};
发布评论

评论列表(0)

  1. 暂无评论