javascript - Rect.setGradient 不是 fabricjs 中的函数
问题描述
我看到有关在fabricjs中将背景设置为渐变的问题。他们说要在 fabric.Rect 的对象上使用 setGradient 但是当我使用它时会导致错误 rect.setGradient is not a function。有什么解决办法吗?谢谢
let rect = new fabric.Rect({
top: 0, left : 0, width : $("canvas").width(), height: $("canvas").height(), fill : "#000"
});
rect.setGradient("fill",{
properties here
})
解决方案
该setGradient
方法在 Fabric v4 中被删除(参见http://fabricjs.com/v4-break-changes)。
这是设置渐变填充的当前方法。
obj.set('fill', new fabric.Gradient({
//gradient options
type: 'linear',
gradientUnits: 'pixels', // or 'percentage'
coords: { x1: 0, y1: 0, x2: 50, y2: 0 },
colorStops:[
{ offset: 0, color: 'red' },
{ offset: 1, color: 'green'}
]
}));
推荐阅读
- video - 防止托管视频被轻松下载
- c# - OnCertificateValidated 未运行 - 自签名证书客户端身份验证 - ASP.NET Core 和 Kestrel
- ios - Swift CoreData,获取所有子实体的问题
- webpack - 升级到最新的 Gatsby 后,Sass base64 背景图片在生产版本中不可用
- postgresql - 如何获得零钱?
- cmake - 如何从单个 CMake 构建中生成目标及其依赖项的多个“风味”?
- java - JavaFX 窗口对于屏幕来说太大了
- android-asynctask - 一类中几个 AsyncTask 的上下文
- php - 如何减慢 AutomateWoo 插件的电子邮件发送速度
- docker-compose - 气流 docker compose 无法访问网络服务器