質問編集履歴
2
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -95,7 +95,6 @@
|
|
95
95
|
let clickPoint=event.target;
|
96
96
|
event.target.classList.add('target');
|
97
97
|
|
98
|
-
//コールバック(登録だけして後で実行する,mmove関数は後で記載するのに使えるのはコールバックだから)
|
99
98
|
table.addEventListener('mousemove',mmove,false);
|
100
99
|
if( clickPoint.classList.contains('target') ){
|
101
100
|
|
@@ -105,8 +104,6 @@
|
|
105
104
|
}
|
106
105
|
|
107
106
|
}
|
108
|
-
|
109
|
-
//コールバック
|
110
107
|
table.addEventListener('mouseup',mup,false);
|
111
108
|
}
|
112
109
|
|
1
コードを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -85,4 +85,54 @@
|
|
85
85
|
}
|
86
86
|
|
87
87
|
table.addEventListener('mousedown',mdown,false);
|
88
|
+
```
|
89
|
+
|
90
|
+
```Javascript
|
91
|
+
|
92
|
+
let table=document.querySelector('.box_cover');
|
93
|
+
|
94
|
+
function mdown(){
|
95
|
+
let clickPoint=event.target;
|
96
|
+
event.target.classList.add('target');
|
97
|
+
|
98
|
+
//コールバック(登録だけして後で実行する,mmove関数は後で記載するのに使えるのはコールバックだから)
|
99
|
+
table.addEventListener('mousemove',mmove,false);
|
100
|
+
if( clickPoint.classList.contains('target') ){
|
101
|
+
|
102
|
+
if( clickPoint.classList.contains('item') ){
|
103
|
+
clickPoint.classList.add('zIndex');
|
104
|
+
clickPoint.classList.add('hover');
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
//コールバック
|
110
|
+
table.addEventListener('mouseup',mup,false);
|
111
|
+
}
|
112
|
+
|
113
|
+
function mmove(){
|
114
|
+
let clickPoint=event.target;
|
115
|
+
console.log(clickPoint);
|
116
|
+
//座標の読み取り
|
117
|
+
let itemHeight=clickPoint.clientHeight/2;
|
118
|
+
let itemWidth=clickPoint.clientWidth/2;
|
119
|
+
|
120
|
+
if( clickPoint.classList.contains('target') ){
|
121
|
+
if( clickPoint.classList.contains('item') ){
|
122
|
+
let pageY=event.pageY;
|
123
|
+
let pageX=event.pageX;
|
124
|
+
clickPoint.style.top=`${pageY-itemHeight}px`;
|
125
|
+
clickPoint.style.left=`${pageX-itemWidth}px`;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
function mup(){
|
132
|
+
table.removeEventListener('mousemove',mmove,false);
|
133
|
+
event.target.classList.remove('target');
|
134
|
+
event.target.classList.remove('zIndex');
|
135
|
+
}
|
136
|
+
|
137
|
+
table.addEventListener('mousedown',mdown,false);
|
88
138
|
```
|