質問編集履歴
2
「表示が延々と続くのですが、関数random外で変数宣言するのと関数random内で宣言するのは何が違うのでしょうか?」の補足を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -47,4 +47,13 @@
|
|
47
47
|
</div>
|
48
48
|
</body>
|
49
49
|
</html>
|
50
|
-
```
|
50
|
+
```
|
51
|
+
###追記
|
52
|
+
「表示が延々と続くのですが、関数random外で変数宣言するのと関数random内で宣言するのは何が違うのでしょうか?」の補足ですが、
|
53
|
+
|
54
|
+
例えば・・・
|
55
|
+
var randomSet = Math.floor(Math.random()*setElm.length);
|
56
|
+
$(setElm[randomSet]).css({visibility:'visible',opacity:'0'}).animate({opacity:'1'},1000);
|
57
|
+
を変数randomSetを使わずに
|
58
|
+
$(setElm[Math.floor(Math.random()*setElm.length)]).css({visibility:'visible',opacity:'0'}).animate({opacity:'1'},1000);
|
59
|
+
と書いたときということです。
|
1
関数名を修正し、コードをコードブロックで囲みました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
また、 Math.floor(Math.random()*setElm.length);を変数宣言しない場合、全ての画像が表示されないのですが、これもどういった理由なのでしょうか。
|
6
6
|
|
7
7
|
###該当のソースコード
|
8
|
+
```ここに言語を入力
|
8
9
|
<!DOCTYPE html>
|
9
10
|
<html xml:lang="ja" lang="ja">
|
10
11
|
<head>
|
@@ -23,7 +24,7 @@
|
|
23
24
|
setElm.splice(randomSet,1);
|
24
25
|
if(setElm.length > 0) {
|
25
26
|
setTimeout(function(){
|
26
|
-
|
27
|
+
random();
|
27
28
|
},100);
|
28
29
|
} else {
|
29
30
|
return false;
|
@@ -45,4 +46,5 @@
|
|
45
46
|
</ul>
|
46
47
|
</div>
|
47
48
|
</body>
|
48
|
-
</html>
|
49
|
+
</html>
|
50
|
+
```
|