回答編集履歴

2

追記

2019/02/03 14:37

投稿

m.ts10806
m.ts10806

スコア80850

test CHANGED
@@ -30,11 +30,11 @@
30
30
 
31
31
  const $win = $(window);
32
32
 
33
- let $winW = $win.innerWidth();
33
+ let $winW = $win.innerWidth();//constでは定数なので定義の形式を変更
34
34
 
35
35
  $win.on('load resize', () => {
36
36
 
37
- $winW = $win.innerWidth();
37
+ $winW = $win.innerWidth();//常にその時の値を取得する
38
38
 
39
39
  if ($winW > 1460) {
40
40
 

1

調整

2019/02/03 14:36

投稿

m.ts10806
m.ts10806

スコア80850

test CHANGED
@@ -26,48 +26,44 @@
26
26
 
27
27
  ```js
28
28
 
29
- $(function(){
29
+ (function ($) {
30
-
31
-
32
30
 
33
31
  const $win = $(window);
34
32
 
35
- var $winW = $win.innerWidth(); //constでは定数なので定義の形式を変更
33
+ let $winW = $win.innerWidth();
36
34
 
37
- $win.on('load resize',() =>{
35
+ $win.on('load resize', () => {
38
36
 
39
- $winW = $win.innerWidth(); //常にその時の値を取得する
37
+ $winW = $win.innerWidth();
40
38
 
41
39
  if ($winW > 1460) {
42
40
 
43
- $('#test p').css('background-color','red');
41
+ $('#test p').css('background-color', 'red');
44
42
 
45
43
  } else if ($winW > 1280) {
46
44
 
47
- $('#test p').css('background-color','yellow');
45
+ $('#test p').css('background-color', 'yellow');
48
46
 
49
47
  } else if ($winW > 960) {
50
48
 
51
- $('#test p').css('background-color','orange');
49
+ $('#test p').css('background-color', 'orange');
52
50
 
53
51
  } else if ($winW > 600) {
54
52
 
55
- $('#test p').css('background-color','green');
53
+ $('#test p').css('background-color', 'green');
56
54
 
57
55
  } else if ($winW > 480) {
58
56
 
59
- $('#test p').css('background-color','blue');
57
+ $('#test p').css('background-color', 'blue');
60
58
 
61
59
  } else {
62
60
 
63
- $('#test p').css('background-color','pink');
61
+ $('#test p').css('background-color', 'pink');
64
62
 
65
63
  }
66
64
 
67
65
  });
68
66
 
69
-
70
-
71
- });
67
+ })(jQuery);
72
68
 
73
69
  ```