質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,3 +3,229 @@
|
|
3
3
|
どなたかお願いします。
|
4
4
|
|
5
5
|
[リンク内容](http://reru12.github.io/test/)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
コード長いので一部ですが、たぶんここら辺を変えると思います。
|
12
|
+
|
13
|
+
```JavaScript
|
14
|
+
|
15
|
+
//106行目から
|
16
|
+
|
17
|
+
function problem()
|
18
|
+
|
19
|
+
{
|
20
|
+
|
21
|
+
var problem;
|
22
|
+
|
23
|
+
var sort_sentence = new Array(problem_number);
|
24
|
+
|
25
|
+
var button_length = 35;
|
26
|
+
|
27
|
+
problem = qarray1[random_number[current_number]].problem_statement;
|
28
|
+
|
29
|
+
document.getElementById('Problem').innerHTML = "";
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
document.getElementById('Answer_time').innerHTML = "残り:"+answer_time[current_number]+"秒";
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// ここで並替ボタンを動的に作る
|
38
|
+
|
39
|
+
// problemを半角空白で分割してボタンにする。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// 問題文の分割
|
44
|
+
|
45
|
+
sort_sentence = problem.split(" ");
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
// 問題文をランダムで並替
|
50
|
+
|
51
|
+
sort_sentence = sort_sentence.slice().sort(function(){ return Math.random() - 0.5; }).slice(0, sort_sentence.length);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// 前回ボタン削除
|
56
|
+
|
57
|
+
del_button();
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
//やり直しボタンの有効化
|
62
|
+
|
63
|
+
if(flg != 2) {
|
64
|
+
|
65
|
+
document.fm.Retry.disabled = false;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// ボタンの作成
|
72
|
+
|
73
|
+
var bi = 1;
|
74
|
+
|
75
|
+
sort_sentence.forEach(function(value) {
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
var sort_buttons = document.getElementById("sort_button_area");
|
80
|
+
|
81
|
+
var element_btn = document.createElement("input");
|
82
|
+
|
83
|
+
element_btn.id = bi;
|
84
|
+
|
85
|
+
element_btn.classList.add("sort_button");
|
86
|
+
|
87
|
+
element_btn.type = "button";
|
88
|
+
|
89
|
+
element_btn.value = value;
|
90
|
+
|
91
|
+
element_btn.setAttribute("onclick", "onbtnClick(" + bi + ");");
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
//ボタンの移動
|
96
|
+
|
97
|
+
element_btn.style.position = "absolute";
|
98
|
+
|
99
|
+
element_btn.style.cursor = "pointer";
|
100
|
+
|
101
|
+
element_btn.style.zIndex = "2";
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
element_btn.ondragstart = function(e){
|
106
|
+
|
107
|
+
return false;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
function onMouseMove(event){
|
114
|
+
|
115
|
+
var x = event.clientX;
|
116
|
+
|
117
|
+
var y = event.clientY;
|
118
|
+
|
119
|
+
var width = element_btn.offsetWidth;
|
120
|
+
|
121
|
+
var height = element_btn.offsetHeight;
|
122
|
+
|
123
|
+
element_btn.style.top = (y-height/2) + "px";
|
124
|
+
|
125
|
+
element_btn.style.left = (x-width/2) + "px";
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
element_btn.onmousedown = function(event){
|
132
|
+
|
133
|
+
document.addEventListener("mousemove",onMouseMove);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
element_btn.onmouseup = function(event){
|
140
|
+
|
141
|
+
var x = event.clientX;
|
142
|
+
|
143
|
+
var y = event.clientY;
|
144
|
+
|
145
|
+
var width = element_btn.offsetWidth;
|
146
|
+
|
147
|
+
var height = element_btn.offsetHeight;
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
document.removeEventListener("mousemove",onMouseMove);//動きを止める
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
// 最低ボタンサイズ(幅)の設定
|
160
|
+
|
161
|
+
if(value.length < 1) {
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
element_btn.setAttribute("style", "width: 5em;");
|
166
|
+
|
167
|
+
button_length = button_length - 5;
|
168
|
+
|
169
|
+
} else {
|
170
|
+
|
171
|
+
button_length = button_length - value.length;
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
// 解答済みの場合のボタン無効化設定
|
180
|
+
|
181
|
+
if(flg == 2 || answers[current_number] != "") {
|
182
|
+
|
183
|
+
element_btn.setAttribute("disabled", true);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
// ボタンの追加
|
190
|
+
|
191
|
+
sort_buttons.appendChild(element_btn);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
bi = bi + 1;
|
196
|
+
|
197
|
+
});
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
// ボタン配置位置
|
202
|
+
|
203
|
+
var area = document.getElementById("sort_button_area");
|
204
|
+
|
205
|
+
if (bi > 8) {
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
area.setAttribute("style", "text-align: center;");
|
210
|
+
|
211
|
+
} else {
|
212
|
+
|
213
|
+
area.setAttribute("style", "text-align: center;");
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if(flg == 2)
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
document.getElementById('Problem').innerHTML = "解答:" + answers[current_number];
|
224
|
+
|
225
|
+
document.getElementById('Correct').innerHTML = "正解:" + qarray1[random_number[current_number]].answer + "";
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|