我想为fabric.js中的形状赋予渐变样式,我想为所有形状编写通用的添加渐变方法,选择对象并单击提交按钮,它应该将填充更改为渐变。
小提琴:: http://jsfiddle.net/jdFet/1/
请检查上面的小提琴,
代码 ::
var canvas;
$(function () {
canvas = window.__canvas = new fabric.Canvas('canvas');
canvas.backgroundColor = '#FFFFFF';
var circle = new fabric.Circle({
left: 100,
top: 100,
radius: 100
});
circle.setGradient('fill',
{ type:'linear',
x1: 0,
y1: 0,
x2: 0,
y2: circle.height,
colorStops: { 0 : 'rgba(0,255,0,1)', 1 : 'rgba(0,0,255,1)'} });
canvas.add(circle);
console.log('Gradient', circle.fill);
});