質問編集履歴

2

コードの変更をしました

2017/10/13 04:52

投稿

meron-pan
meron-pan

スコア44

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,39 @@
6
6
 
7
7
  ```JavaScript
8
8
 
9
+ //Canvas1の下にCanvas2が存在する
10
+
11
+ function button1(x, y, width, height){
12
+
13
+ ctx1.rect(x, y, width, height);
14
+
15
+ ctx1.stroke();
16
+
9
- canvas.addEventListener('click', function(e){
17
+ canvas1.addEventListener('click', function(e){
18
+
19
+ var button = e.target.getBoundingClientRect();
20
+
21
+ mouseX = e.clientX - button.left;
22
+
23
+ mouseY = e.clientY - button.top;
24
+
25
+           if(x < mouseX && mouseX < x + width){
26
+
27
+ if(y < mouseY && mouseY < y + height){
28
+
29
+               *ここに処理を書く
30
+
31
+           }
32
+
33
+ //反応しない
34
+
35
+ function button2(x, y, width, height){
36
+
37
+ ctx2.rect(x, y, width, height);
38
+
39
+ ctx2.stroke();
40
+
41
+ canvas2.addEventListener('click', function(e){
10
42
 
11
43
  var button = e.target.getBoundingClientRect();
12
44
 

1

コードを追加しました

2017/10/13 04:52

投稿

meron-pan
meron-pan

スコア44

test CHANGED
File without changes
test CHANGED
@@ -13,6 +13,14 @@
13
13
  mouseX = e.clientX - button.left;
14
14
 
15
15
  mouseY = e.clientY - button.top;
16
+
17
+           if(x < mouseX && mouseX < x + width){
18
+
19
+ if(y < mouseY && mouseY < y + height){
20
+
21
+               *ここに処理を書く
22
+
23
+           }
16
24
 
17
25
  ```
18
26