質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,116 @@
|
|
1
1
|
英語の並び替えをしたいのですが、以下のリンクの通り、ボタン(英語のやつ)を作成したところ初期状態のボタンが重なってしまい選択しにくい状態になっています。このボタンを今の動かせる状態を維持したまま、初期状態から等間隔で横並びできるようにしたいのですがやり方がわかりません。146行目のabsoluteを入力するとボタンが重なってしまいました。
|
2
2
|
どなたかお願いします。
|
3
|
-
[リンク内容](http://reru12.github.io/test/)
|
3
|
+
[リンク内容](http://reru12.github.io/test/)
|
4
|
+
|
5
|
+
|
6
|
+
コード長いので一部ですが、たぶんここら辺を変えると思います。
|
7
|
+
```JavaScript
|
8
|
+
//106行目から
|
9
|
+
function problem()
|
10
|
+
{
|
11
|
+
var problem;
|
12
|
+
var sort_sentence = new Array(problem_number);
|
13
|
+
var button_length = 35;
|
14
|
+
problem = qarray1[random_number[current_number]].problem_statement;
|
15
|
+
document.getElementById('Problem').innerHTML = "";
|
16
|
+
|
17
|
+
document.getElementById('Answer_time').innerHTML = "残り:"+answer_time[current_number]+"秒";
|
18
|
+
|
19
|
+
// ここで並替ボタンを動的に作る
|
20
|
+
// problemを半角空白で分割してボタンにする。
|
21
|
+
|
22
|
+
// 問題文の分割
|
23
|
+
sort_sentence = problem.split(" ");
|
24
|
+
|
25
|
+
// 問題文をランダムで並替
|
26
|
+
sort_sentence = sort_sentence.slice().sort(function(){ return Math.random() - 0.5; }).slice(0, sort_sentence.length);
|
27
|
+
|
28
|
+
// 前回ボタン削除
|
29
|
+
del_button();
|
30
|
+
|
31
|
+
//やり直しボタンの有効化
|
32
|
+
if(flg != 2) {
|
33
|
+
document.fm.Retry.disabled = false;
|
34
|
+
}
|
35
|
+
|
36
|
+
// ボタンの作成
|
37
|
+
var bi = 1;
|
38
|
+
sort_sentence.forEach(function(value) {
|
39
|
+
|
40
|
+
var sort_buttons = document.getElementById("sort_button_area");
|
41
|
+
var element_btn = document.createElement("input");
|
42
|
+
element_btn.id = bi;
|
43
|
+
element_btn.classList.add("sort_button");
|
44
|
+
element_btn.type = "button";
|
45
|
+
element_btn.value = value;
|
46
|
+
element_btn.setAttribute("onclick", "onbtnClick(" + bi + ");");
|
47
|
+
|
48
|
+
//ボタンの移動
|
49
|
+
element_btn.style.position = "absolute";
|
50
|
+
element_btn.style.cursor = "pointer";
|
51
|
+
element_btn.style.zIndex = "2";
|
52
|
+
|
53
|
+
element_btn.ondragstart = function(e){
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
function onMouseMove(event){
|
58
|
+
var x = event.clientX;
|
59
|
+
var y = event.clientY;
|
60
|
+
var width = element_btn.offsetWidth;
|
61
|
+
var height = element_btn.offsetHeight;
|
62
|
+
element_btn.style.top = (y-height/2) + "px";
|
63
|
+
element_btn.style.left = (x-width/2) + "px";
|
64
|
+
}
|
65
|
+
|
66
|
+
element_btn.onmousedown = function(event){
|
67
|
+
document.addEventListener("mousemove",onMouseMove);
|
68
|
+
}
|
69
|
+
|
70
|
+
element_btn.onmouseup = function(event){
|
71
|
+
var x = event.clientX;
|
72
|
+
var y = event.clientY;
|
73
|
+
var width = element_btn.offsetWidth;
|
74
|
+
var height = element_btn.offsetHeight;
|
75
|
+
|
76
|
+
document.removeEventListener("mousemove",onMouseMove);//動きを止める
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
// 最低ボタンサイズ(幅)の設定
|
81
|
+
if(value.length < 1) {
|
82
|
+
|
83
|
+
element_btn.setAttribute("style", "width: 5em;");
|
84
|
+
button_length = button_length - 5;
|
85
|
+
} else {
|
86
|
+
button_length = button_length - value.length;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
// 解答済みの場合のボタン無効化設定
|
91
|
+
if(flg == 2 || answers[current_number] != "") {
|
92
|
+
element_btn.setAttribute("disabled", true);
|
93
|
+
}
|
94
|
+
|
95
|
+
// ボタンの追加
|
96
|
+
sort_buttons.appendChild(element_btn);
|
97
|
+
|
98
|
+
bi = bi + 1;
|
99
|
+
});
|
100
|
+
|
101
|
+
// ボタン配置位置
|
102
|
+
var area = document.getElementById("sort_button_area");
|
103
|
+
if (bi > 8) {
|
104
|
+
|
105
|
+
area.setAttribute("style", "text-align: center;");
|
106
|
+
} else {
|
107
|
+
area.setAttribute("style", "text-align: center;");
|
108
|
+
}
|
109
|
+
|
110
|
+
if(flg == 2)
|
111
|
+
{
|
112
|
+
document.getElementById('Problem').innerHTML = "解答:" + answers[current_number];
|
113
|
+
document.getElementById('Correct').innerHTML = "正解:" + qarray1[random_number[current_number]].answer + "";
|
114
|
+
}
|
115
|
+
}
|
116
|
+
```
|