Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.0/fabric.min.js"></script>

<canvas id="canvas_in_html" width="300" height="200" style="border:5px solid; border-color:#999999;"></canvas>
              
            
!

CSS

              
                
              
            
!

JS

              
                //htmlで作ったcanvas要素をidで指定して、canvasオブジェクトを生成。
const canvas = new fabric.Canvas("canvas_in_html");

//サイズを設定。後から変更できる
canvas.setWidth(300);
canvas.setHeight(200);

//フリードローイングを可能にする
canvas.isDrawingMode = true;

//背景色を設定。4つ目はアルファ(不透明度)。PNGでDLするときも有効
canvas.setBackgroundColor(
  "rgba(255, 255, 200, 1)",
  canvas.renderAll.bind(canvas)
);

//描画色の設定。RGB+不透明度。"rgb(255,50,40)"と書くとアルファを省略できる
canvas.freeDrawingBrush.color = "rgba(255,50,40,0.5)"; // 描画する線の色 rgba

//ペンサイズの設定
canvas.freeDrawingBrush.width = 10; // 描画する線の太さ

// 全消し
//canvas.clear();
//バックグラウンドも消えるので、
//再度canvas.setBackgroundColorする必要がある

              
            
!
999px

Console