fabric.js使用旋转手柄将旋转限制为x度 [英] fabric.js limit rotation to x degrees with rotation handle

查看:351
本文介绍了fabric.js使用旋转手柄将旋转限制为x度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用fabric.js并尝试使用旋转手柄允许画布上的任何对象自由旋转360度,但一次只能旋转15度.我非常努力地搜寻,但到目前为止找不到答案.这可能吗?

I am using fabric.js and trying to allow rotation for any object on my canvas, not freely 360 degrees, but only 15 degrees at a time, using the rotation handle. I searched really hard but couldn't find an answer so far. Is this possible?

推荐答案

更短的解决方案:

canvas.on('object:rotating', function(options) {
  var step = 15;
  options.target.angle = Math.round(options.target.angle / step) * step;
});

UPD::自1.6.7开始,您可以使用fabric.Object.snapAngle属性:

UPD: since 1.6.7 you can just use fabric.Object.snapAngle property:

someFabricObject.snapAngle = 15;

这篇关于fabric.js使用旋转手柄将旋转限制为x度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆