質問編集履歴
3
JSファイルであることを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,9 +52,9 @@
|
|
52
52
|
|
53
53
|
```
|
54
54
|
|
55
|
-
|
55
|
+
JavaScriptの該当部分は下記です。
|
56
|
-
|
56
|
+
|
57
|
-
```JavaScript
|
57
|
+
```JavaScript
|
58
58
|
|
59
59
|
const overlay = document.querySelector('.overlay');
|
60
60
|
|
@@ -82,9 +82,9 @@
|
|
82
82
|
|
83
83
|
```
|
84
84
|
|
85
|
-
|
85
|
+
JavaScriptの全文も記載します。
|
86
|
-
|
86
|
+
|
87
|
-
```JavaScript
|
87
|
+
```JavaScript
|
88
88
|
|
89
89
|
const displayedImage = document.querySelector('.displayed-img');
|
90
90
|
|
2
全文を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
```JavaScript
|
57
|
+
```JavaScript該当部分
|
58
58
|
|
59
59
|
const overlay = document.querySelector('.overlay');
|
60
60
|
|
@@ -82,6 +82,112 @@
|
|
82
82
|
|
83
83
|
```
|
84
84
|
|
85
|
+
|
86
|
+
|
87
|
+
```JavaScript全文
|
88
|
+
|
89
|
+
const displayedImage = document.querySelector('.displayed-img');
|
90
|
+
|
91
|
+
const thumbBar = document.querySelector('.thumb-bar');
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
const btn = document.querySelector('button');
|
96
|
+
|
97
|
+
const overlay = document.querySelector('.overlay');
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
/* Looping through images */
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
createImages();
|
106
|
+
|
107
|
+
function createImages(){
|
108
|
+
|
109
|
+
for(let i = 1; i<6; i++){
|
110
|
+
|
111
|
+
let newImage = document.createElement('img');
|
112
|
+
|
113
|
+
newImage.setAttribute('src',"images/pic" + i + ".jpg ");
|
114
|
+
|
115
|
+
newImage.setAttribute("id","image" + i);
|
116
|
+
|
117
|
+
thumbBar.appendChild(newImage);
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
changeMainPic();
|
126
|
+
|
127
|
+
function changeMainPic(){
|
128
|
+
|
129
|
+
for(let i=1; i<6; i++){
|
130
|
+
|
131
|
+
let imgBtn = document.getElementById("image" + i);
|
132
|
+
|
133
|
+
console.log(imgBtn);
|
134
|
+
|
135
|
+
imgBtn.addEventListener("click",function(){
|
136
|
+
|
137
|
+
displayedImage.setAttribute("src", "images/pic" + i + ".jpg")
|
138
|
+
|
139
|
+
});
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/* Wiring up the Darken/Lighten button */
|
148
|
+
|
149
|
+
//無名関数の利用
|
150
|
+
|
151
|
+
btn.onclick = function(e){
|
152
|
+
|
153
|
+
if(e.target.textContent === "Darken"){
|
154
|
+
|
155
|
+
e.target.setAttribute("class","light");
|
156
|
+
|
157
|
+
e.target.textContent = "Lighten";
|
158
|
+
|
159
|
+
overlay.style.backgroundColor = "rgba(0,0,0,0.5)";
|
160
|
+
|
161
|
+
//overlay.style.opacity = 0.5;
|
162
|
+
|
163
|
+
//overlay.fillStyle = rgba(0,0,0,0.5);
|
164
|
+
|
165
|
+
//overlay.style.setAttribute("background-color","rgba(0,0,0,5)");
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
else{
|
170
|
+
|
171
|
+
e.target.setAttribute("class","dark");
|
172
|
+
|
173
|
+
e.target.textContent = "Darken";
|
174
|
+
|
175
|
+
overlay.style.backgroundColor = "rgba(0,0,0,0)";
|
176
|
+
|
177
|
+
//overlay.style.opacity = 0;
|
178
|
+
|
179
|
+
//overlay.fillStyle = rgba(0,0,0,0);
|
180
|
+
|
181
|
+
//overlay.style.setAttribute("background-color","rgba(0,0,0,0)");
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|
190
|
+
|
85
191
|
上記のJavaScript側の最後の3行の書き方ではいずれもrgba()の値を設定することが出来ません。
|
86
192
|
|
87
193
|
特になぜsetAttributeのブラウザ組み込み関数が使えないのは、既にCSSのファイルでrgba()の値が設定されているからかな、、、?
|
1
overlay変数の宣言/初期化を記入。
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,6 +56,10 @@
|
|
56
56
|
|
57
57
|
```JavaScript
|
58
58
|
|
59
|
+
const overlay = document.querySelector('.overlay');
|
60
|
+
|
61
|
+
|
62
|
+
|
59
63
|
btn.onclick = function(e){
|
60
64
|
|
61
65
|
if(e.target.textContent === "Darken"){
|