質問編集履歴
1
MediaQueryListでも解決できなかったため変更後のコードを追加します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,123 @@
|
|
37
37
|
```
|
38
38
|
|
39
39
|
if()のところにtrue,falseを入れるにはどうすればいいのでしょうか?
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
##追加
|
46
|
+
|
47
|
+
MediaQueryListを使っても思い通りの結果にならなかったのでif文のコードも追加します。
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
if (e.matches){
|
52
|
+
|
53
|
+
var timer = setInterval(function() {
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
(indexSlider).fadeOut("slow").removeClass(BGsize[index]);
|
58
|
+
|
59
|
+
index=(index+1)%4;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
(indexSlider).fadeIn("slow").delay(2000).addClass(BGsize[index]);
|
64
|
+
|
65
|
+
console.log("大きい"+af);
|
66
|
+
|
67
|
+
}, 3000);
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
以下関連の全コード
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
var af=window.matchMedia("(max-width:767px)");
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
function testes(e){
|
84
|
+
|
85
|
+
if (e.matches){
|
86
|
+
|
87
|
+
var timer = setInterval(function() {
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
(indexSlider).fadeOut("slow").removeClass(BGsize[index]);
|
92
|
+
|
93
|
+
index=(index+1)%4;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
(indexSlider).fadeIn("slow").addClass(BGsize[index]);
|
98
|
+
|
99
|
+
}, 3000);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
else{var timer = setInterval(function() {
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
(indexSlider).fadeOut("slow").removeClass(SMsize[index]);
|
110
|
+
|
111
|
+
index=(index+1)%4;
|
112
|
+
|
113
|
+
(indexSlider).fadeIn("slow").addClass(SMsize[index]);
|
114
|
+
|
115
|
+
}, 5000);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
af.addListener(testes);
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
///下記のコードで初期値で入れていました。コードを変えたことでこれも問題あるとわかるのですが解決ができていないためそのまま載せます。
|
132
|
+
|
133
|
+
if (!af.matches){
|
134
|
+
|
135
|
+
indexSlider.addClass(BGsize[0]);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
else if(af.matches){
|
140
|
+
|
141
|
+
indexSlider.addClass(SMsize[0]);
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
///ここまで
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
MediaQueryListを使ってダメだった点:
|
150
|
+
|
151
|
+
1.767サイズより大きいサイズだった場合if(e.matches)=trueが反応しない。動的に小さくなった時にtrueの処理が始まる。
|
152
|
+
|
153
|
+
2.767サイズより小さい場合elseの処理が始まらない。動的に大きくなりまた小さくなると処理が始まるが,if trueとelseの両方の処理が繰り返される。
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
実現したいことウィンドウを開いたとき画面サイズを所得してif文(繰り返させるtimer)を起動させる。
|
158
|
+
|
159
|
+
サイズが変わった時、処理を終了(繰り返しのtimerを停止)させてif文を実行する。(現状だと両方実行してしまうため)
|