質問編集履歴

2

試したこと追加、タイトル修正

2022/09/09 06:20

投稿

coool
coool

スコア29

test CHANGED
@@ -1 +1 @@
1
- Fabric.jsを使用してcanvasを複数設置したい
1
+ Fabric.jsを使用してcanvasを複数設置したいが、二つめのcanvasにレイヤーが作成されない
test CHANGED
@@ -4,7 +4,10 @@
4
4
 
5
5
  ### 発生している問題・エラーメッセージ
6
6
  一つ目の自由描画のcanvasは問題なく動作しますが、二つ目のテキスト配置のcanvasは配置したテキストが表示されません。
7
+
8
+ ### 試したこと
9
+ Chromeの開発ツールでみてみると、id:csnvas-finalの方は.lower-canvasと.upper-canvasどちらの要素も加わっておらず、レイヤーが作成されていない状況になります。
7
- canvasは複数枚数使用きないなどの制約があるのでょうか?
10
+ classm名を分けてもだめでした。
8
11
 
9
12
  ### 該当のソースコード
10
13
 
@@ -34,7 +37,7 @@
34
37
  <div style="padding:10px">
35
38
  <button id="delete" style="display:none">選択範囲削除</button>
36
39
  </div>
37
- <canvas id="canvas-id" width="800" height="400" class="canvas"></canvas>
40
+ <canvas id="canvas-id" width="800" height="400" class="canvas1"></canvas>
38
41
  <div style="padding:10px">
39
42
  <button type="button" onclick="chgImg()" value="1">画像変換</button>
40
43
  <h2>画像出力欄</h2>
@@ -43,8 +46,7 @@
43
46
  </div>
44
47
 
45
48
  <h1>テキスト</h1>
46
- <div class="canvas-container2" style="width: 800px; height: 1000px; position: relative; user-select: none;">
47
- <canvas id="canvas-final" width="800" height="1000" class="canvas"></canvas>
49
+ <canvas id="canvas-final" width="800" height="1000" class="canvas2"></canvas>
48
50
  </div>
49
51
 
50
52
 

1

タグの誤り修正・余分なコード削除

2022/09/09 05:45

投稿

coool
coool

スコア29

test CHANGED
File without changes
test CHANGED
@@ -9,10 +9,6 @@
9
9
  ### 該当のソースコード
10
10
 
11
11
  ```HTML&Jquery
12
- <!DOCTYPE html>
13
- <html>
14
-
15
- <head>
16
12
  <!DOCTYPE html>
17
13
  <html>
18
14
 
@@ -20,6 +16,8 @@
20
16
  <base target="_top">
21
17
  <?!=HtmlService.createHtmlOutputFromFile('css.html').getContent(); ?>
22
18
  <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
19
+ <link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
20
+ <!---HTML5 canvasのフレームワーク--->
23
21
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.4.0/fabric.min.js"></script>
24
22
  </head>
25
23
 
@@ -28,14 +26,6 @@
28
26
  <br>
29
27
  <center>
30
28
 
31
- <button type="button" id="modalOpen" class="button" data-target="modal1">canvas</button>
32
- </center>
33
- <br><br>
34
-
35
-
36
- <!--- モーダルウィンドウ --->
37
-
38
- <div id="modal1" class="modal_box">
39
29
  <h1>自由描画ウィンドウ</h1>
40
30
  <label style="font-size: 20px; color: red;"> <input id="drawing" type="checkbox"
41
31
  checked><b>編集</b></label><br><br>
@@ -50,123 +40,28 @@
50
40
  <h2>画像出力欄</h2>
51
41
  <div id="img-box"><img id="newImg"></div>
52
42
 
53
- <div class="link_area">
54
- <p class="modal_link"><a data-target="modal2" class="modal_switch"><span>テキストへ</span></a></p>
55
- </div>
56
-
57
- <p><a class="modal_close">×<i class="zmdi zmdi-close"></i></a></p>
58
43
  </div>
59
- </div>
44
+
60
-
61
-
62
-
63
- <div id="modal2" class="modal_box">
64
45
  <h1>テキスト</h1>
65
46
  <div class="canvas-container2" style="width: 800px; height: 1000px; position: relative; user-select: none;">
66
47
  <canvas id="canvas-final" width="800" height="1000" class="canvas"></canvas>
67
48
  </div>
68
49
 
69
- <div class="link_area">
70
- <ul>
71
- <li class="modal_link"><a data-target="modal1" class="modal_switch"
72
- rel="noopener noreferrer"><span>自由描画へ</span></a></li>
73
- </ul>
74
- </div>
75
- <p><a class="modal_close">×<i class="zmdi zmdi-close"></i></a></p>
76
- </div>
77
-
78
50
 
79
51
  </div>
80
52
 
81
- <!--- 終わり --->
82
53
 
83
54
  <script>
84
55
  const buttonOpen = document.getElementById('modalOpen');
85
56
  const modal = document.getElementById('easyModal');
86
57
  const buttonClose = document.getElementsByClassName('modalClose')[0];
87
58
 
88
-
59
+
60
+
89
- /*--------------
61
+ /*----------------------------------
90
- ボタンクリック
91
- ----------------*/
92
- $(function () {
93
- // 「.modal_open」をクリックしたらモーダルと黒い背景を表示する
94
- $('#modalOpen').click(function () {
95
-
96
- // 黒い背景をbody内に追加
97
- $('body').append('<div class="modal_bg"></div>');
98
- $('.modal_bg').fadeIn();
99
-
100
- // data-targetの内容をIDにしてmodalに代入
101
- var modal = '#' + $(this).attr('data-target');
102
-
103
- // モーダルをウィンドウの中央に配置する
104
- function modalResize() {
105
- var w = $(window).width();
106
- var h = $(window).height();
107
-
108
- var x = (w - $(modal).outerWidth(true)) / 2;
109
- var y = (h - $(modal).outerHeight(true)) / 2;
110
-
111
- $(modal).css({ 'left': x + 'px', 'top': y + 'px' });
112
- }
113
-
114
- // modalResizeを実行
115
- modalResize();
116
-
117
- // modalをフェードインで表示
118
- $(modal).fadeIn();
119
-
120
- // .modal_bgか.modal_closeをクリックしたらモーダルと背景をフェードアウトさせる
121
- $('.modal_bg, .modal_close').off().click(function () {
122
- $('.modal_box').fadeOut();
123
- $('.modal_bg').fadeOut('slow', function () {
124
- $('.modal_bg').remove();
125
- });
126
- });
127
-
128
- // ウィンドウがリサイズされたらモーダルの位置を再計算する
129
- $(window).on('resize', function () {
130
- modalResize();
131
- });
132
-
133
- // .modal_switchを押すとモーダルを切り替える
134
- $('.modal_switch').click(function () {
135
-
136
- // 押された.modal_switchの親要素の.modal_boxをフェードアウトさせる
137
- $(this).parents('.modal_box').fadeOut();
138
-
139
- // 押された.modal_switchのdata-targetの内容をIDにしてmodalに代入
140
- var modal = '#' + $(this).attr('data-target');
141
-
142
- // モーダルをウィンドウの中央に配置する
143
- function modalResize() {
144
- var w = $(window).width();
145
- var h = $(window).height();
146
-
147
- var x = (w - $(modal).outerWidth(true)) / 2;
148
- var y = (h - $(modal).outerHeight(true)) / 2;
149
-
150
- $(modal).css({ 'left': x + 'px', 'top': y + 'px' });
151
- }
152
-
153
- // modalResizeを実行
154
- modalResize();
155
-
156
- $(modal).fadeIn();
157
-
158
- // ウィンドウがリサイズされたらモーダルの位置を再計算する
159
- $(window).on('resize', function () {
160
- modalResize();
161
- });
162
- });
163
- });
164
- });
165
-
166
-
167
- /*-------------
168
-  自由描画スクリプト
62
+ 自由描画スクリプト
169
- ---------------*/
63
+ -----------------------------------*/
64
+
170
65
  //htmlで作ったcanvas要素をidで指定して、canvasオブジェクトを生成。
171
66
  const canvas = new fabric.Canvas("canvas-id");
172
67
 
@@ -268,9 +163,9 @@
268
163
  }, 0);
269
164
  }
270
165
 
271
- /*-----------
166
+ /*----------------------------------
272
167
  テキスト
273
- -------------*/
168
+ -----------------------------------*/
274
169
  var canvasf = new fabric.Canvas('canvas-final');
275
170
 
276
171
  var textObj = new fabric.Text('Hello Text!', {
@@ -302,104 +197,7 @@
302
197
  font-family: "Open Sans", sans-serif;
303
198
  line-height: 1.25;
304
199
  }
305
- @media screen and (min-width: 800px) {
200
+
306
- .modal_box {
307
- position: fixed;
308
- z-index: 7777;
309
- display: none;
310
- width: 80%;
311
- height: 500px;
312
- max-width: 1000px;
313
- margin: 0;
314
- padding: 60px 2vw 80px;
315
- border: 2px solid #aaa;
316
- text-align: center;
317
- background: #fff;
318
- box-sizing: border-box;
319
- overflow: scroll;
320
- }
321
-
322
- .modal_close {
323
- position: absolute;
324
- top: 0;
325
- right: 0;
326
- display: block;
327
- width: 62px;
328
- font-size: 46px;
329
- color: #000;
330
- line-height: 62px;
331
- text-align: center;
332
- background: #e6e6e6;
333
- }
334
-
335
- .modal_close i {
336
- line-height: 62px;
337
- vertical-align: bottom;
338
- }
339
-
340
- .modal_bg {
341
- position: fixed;
342
- top: 0;
343
- left: 0;
344
- z-index: 6666;
345
- display: none;
346
- width: 100%;
347
- height: 120%;
348
- background-color: rgba(0, 0, 0, 0.7);
349
- }
350
-
351
-
352
- }
353
-
354
-
355
- @media screen and (max-width: 769px) {
356
- /* ウィンドウサイズ769px以下の時のスタイル */
357
- .modal_box {
358
- position: fixed;
359
- z-index: 7777;
360
- display: none;
361
- width: 80%;
362
- height: 500px;
363
- max-width: 1000px;
364
- margin: 0;
365
- padding: 60px 2vw 80px;
366
- border: 2px solid #aaa;
367
- text-align: center;
368
- background: #fff;
369
- box-sizing: border-box;
370
- overflow: scroll;
371
- }
372
-
373
- .modal_close {
374
- position: absolute;
375
- top: 0;
376
- right: 0;
377
- display: block;
378
- width: 62px;
379
- font-size: 46px;
380
- color: #000;
381
- line-height: 62px;
382
- text-align: center;
383
- background: #e6e6e6;
384
- }
385
-
386
- .modal_close i {
387
- line-height: 62px;
388
- vertical-align: bottom;
389
- }
390
-
391
- .modal_bg {
392
- position: fixed;
393
- top: 0;
394
- left: 0;
395
- z-index: 6666;
396
- display: none;
397
- width: 100%;
398
- height: 120%;
399
- background-color: rgba(0, 0, 0, 0.7);
400
- }
401
-
402
- }
403
201
 
404
202
  canvas {
405
203
  border: 3px solid #000;