当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Fabric.js Group flipY属性用法及代码示例


在本文中,我们将看到如何使用Fabric.js设置画布组的flipY。 Fabric.js中的组是可移动的,可以根据需要进行拉伸。此外,当涉及初始笔划颜色,高度,宽度,填充颜色或笔划宽度时,可以自定义组。

方法:

  • 为了使之成为可能,我们将使用一个名为Fabric.js的JavaScript HTML5画布库。
  • 导入库后,我们将在body标签中创建一个画布块,其中将包含Group。
  • 之后,我们将初始化Fabric.js提供的Canvas和Group实例,并使用flipY属性垂直翻转canvas组。

用法:

fabric.Group([canvas1, canvas2], {
   flipY:Boolean
});

参数:该属性接受上述和以下描述的单个参数:

  • flipY:它指定对象垂直翻转。

以下示例说明了JavaScript中Fabric.js Group flipY属性的用法:



范例1:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
  <!-- FabricJS CDN -->
  <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
  </script> 
  
</head> 
  
<body> 
    <div style="text-align:center;width:400px;"> 
      <h1 style="color:green;"> 
          GeeksforGeeks 
      </h1> 
      <b> 
          Fabric.js | Group flipY Property 
      </b> 
    </div> 
    
    <div style="text-align:center;"> 
      <canvas id="canvas" width="500" height="300"
      style="border:1px solid green;"> 
      </canvas> 
    </div> 
    
    <script> 
      // Initiate a Canvas instance 
      var canvas = new fabric.Canvas("canvas"); 
        
      // Initiate a circle instance 
      var circle = new fabric.Circle({ 
        radius:100, 
        fill:'lightgreen', 
        scaleY:0.6, 
        originX:'center', 
        originY:'center' 
      }); 
  
      // Initiate a text instance 
      var text = new fabric.Text('GeeksforGeeks', { 
        fontSize:25, 
        originX:'center', 
        originY:'center' 
      }); 
  
      // Initiate a Group instance 
      var group = new fabric.Group([ circle, text ], { 
        flipY:true      
      }); 
  
      // Render the Group in canvas 
      canvas.add(group); 
  
      // Center the Group in canvas 
      canvas.centerObject(group); 
  </script> 
</body> 
  
</html>

输出:

范例2:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
  <!-- FabricJS CDN -->
  <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
  </script> 
  
</head> 
  
<body> 
    <div style="text-align:center;width:400px;"> 
      <h1 style="color:green;"> 
          GeeksforGeeks 
      </h1> 
      <b> 
          Fabric.js | Group flipY Property 
      </b> 
    </div> 
    
    <div style="text-align:center;"> 
      <canvas id="canvas" width="500" height="300"
      style="border:1px solid green;"> 
      </canvas> 
    </div> 
    
    <script> 
      // Initiate a Canvas instance 
      var canvas = new fabric.Canvas("canvas"); 
        
      // Initiate a circle instance 
      var circle = new fabric.Circle({ 
        radius:100, 
        fill:'lightgreen', 
        scaleY:0.6, 
        originX:'center', 
        originY:'center' 
      }); 
  
      // Initiate a text instance 
      var text = new fabric.Text('GeeksforGeeks', { 
        fontSize:25, 
        originX:'center', 
        originY:'center' 
      }); 
  
      // Initiate a Group instance 
      var group = new fabric.Group([ circle, text ], { 
        flipY:false      
      }); 
  
      // Render the Group in canvas 
      canvas.add(group); 
  
      // Center the Group in canvas 
      canvas.centerObject(group); 
  </script> 
</body> 
  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自thacker_shahid大神的英文原创作品 Fabric.js Group flipY Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。