FabricJS를 사용하여 Ellipse의 중심 크기 조정을 비활성화하는 방법은 무엇입니까?

王林
풀어 주다: 2023-09-17 09:25:02
앞으로
1083명이 탐색했습니다.

如何使用 FabricJS 禁用 Ellipse 的居中缩放?

이 튜토리얼에서는 FabricJS를 사용하여 Ellipse의 Centered Zoom을 비활성화하는 방법을 알아봅니다. 타원은 FabricJS에서 제공하는 다양한 모양 중 하나입니다. 타원을 생성하려면 Fabric.Ellipse 클래스의 인스턴스를 생성하여 캔버스에 추가해야 합니다. 컨트롤을 통해 크기를 조정할 때 centeredScaling 속성에 "true" 값을 할당하여 중심을 개체의 변형 원점으로 사용합니다.

Syntax

new fabric.Ellipse({ centeredScaling: Boolean }: Object)
로그인 후 복사

Parameters

  • Options(선택 사항) - 이 매개 변수는 타원에 대한 추가 사용자 정의를 제공하는 object< /em>입니다. 이 매개변수를 사용하면 centeredScaling 속성과 관련된 개체의 색상, 커서, 획 너비 및 기타 여러 속성을 변경할 수 있습니다.

Option Key

  • centeredScaling - 이 속성은 boolean 값을 허용합니다. 이 속성이 True인 경우 개체는 중심을 변환 원점으로 사용합니다.

예제 1

centeredScaling을 키로 전달하고 "true" 값 할당

다음 예는 centeredScaling 속성이 활성화되었을 때 타원 객체가 어떻게 동작하는지 보여줍니다. 객체를 확대할 때 변형의 원점은 타원의 중심입니다.

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>How to disable the centered scaling of Ellipse using FabricJS?</h2>
      <p>Select the object and stretch it from its corners. The ellipse will scale up from its center. This is the default behavior.</p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 215,
            top: 100,
            fill: "white",
            rx: 90,
            ry: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            centeredScaling: true,
         });

         // Adding it to the canvas
         canvas.add(ellipse);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>
로그인 후 복사

예 2

centeredScaling 속성 비활성화

"false" 값을 할당하여 centeredScaling 속성을 비활성화할 수 있습니다. 그러면 더 이상 타원 중심을 변환 중심으로 사용하지 않습니다. 데모용 코드는 다음과 같습니다 -

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>How to disable the centered scaling of Ellipse using FabricJS?</h2>
      <p>Select the object and stretch it from its corners. You will notice the object scales up but not from its center because we have set <b>centeredScaling</b> as False. </p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 215,
            top: 100,
            fill: "",
            rx: 90,
            ry: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            centeredScaling: false,
         });

         // Adding it to the canvas
         canvas.add(ellipse);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>
로그인 후 복사

위 내용은 FabricJS를 사용하여 Ellipse의 중심 크기 조정을 비활성화하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!