回答編集履歴
1
修正
test
CHANGED
@@ -54,17 +54,17 @@
|
|
54
54
|
|
55
55
|
<script>
|
56
56
|
|
57
|
-
function setRandomLeft() {
|
57
|
+
function setRandomLeft(imageWidth) {
|
58
58
|
|
59
|
-
return (Math.random() * (document.getElementById("content").clientWidth -
|
59
|
+
return (Math.random() * (document.getElementById("content").clientWidth - imageWidth)) + "px";
|
60
60
|
|
61
61
|
}
|
62
62
|
|
63
63
|
|
64
64
|
|
65
|
-
function setRandomTop() {
|
65
|
+
function setRandomTop(imageHeight) {
|
66
66
|
|
67
|
-
return (Math.random() * (document.getElementById("content").clientHeight -
|
67
|
+
return (Math.random() * (document.getElementById("content").clientHeight - imageHeight)) + "px";
|
68
68
|
|
69
69
|
}
|
70
70
|
|
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
document.getElementById("btn").addEventListener("click", function () {
|
74
74
|
|
75
|
-
document.getElementById("content").innerHTML = "";
|
75
|
+
document.getElementById("content").innerHTML = "";
|
76
76
|
|
77
77
|
var image = document.createElement("img");
|
78
78
|
|
@@ -80,9 +80,9 @@
|
|
80
80
|
|
81
81
|
image.style.position = "absolute";
|
82
82
|
|
83
|
-
image.style.top = setRandomTop();
|
83
|
+
image.style.top = setRandomTop("100");//画像の横の長さをsetRandomTopに。
|
84
84
|
|
85
|
-
image.style.left = setRandomLeft();
|
85
|
+
image.style.left = setRandomLeft("100");//画像の縦の長さをsetRandomLeftに。
|
86
86
|
|
87
87
|
document.getElementById("content").appendChild(image);
|
88
88
|
|