teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2017/10/12 01:41

投稿

yambejp
yambejp

スコア117885

answer CHANGED
@@ -9,6 +9,9 @@
9
9
  $(function() {
10
10
  $('.box').addClass('hide');
11
11
  $('.btn span:nth-child(2)').addClass('hide');
12
+ /* 追記:5件以下の場合は、もっと見るボタンを非表示*/
13
+ $('.box .list:not(:has(li:nth-child(6)))').next('.btn').find('span').addClass('hide');
14
+
12
15
  $('.btn').on('click',function(){
13
16
  $(this).closest('.box').toggleClass('hide');
14
17
  $(this).find('span').toggleClass('hide');

1

追記

2017/10/12 01:41

投稿

yambejp
yambejp

スコア117885

answer CHANGED
@@ -53,4 +53,54 @@
53
53
  </div>
54
54
  </div>
55
55
 
56
+ ```
57
+
58
+ # 追記
59
+ idを付けたチェックボックスをスイッチにしていいならjavascriptもいりません
60
+ ```CSS
61
+ input.switch{position:absolute;top:-9999px;}
62
+ input:checked+.box li:nth-child(n+6){display:none;}
63
+ .box label span:nth-child(1){display:none;}
64
+ input:checked+.box label span:nth-child(1){display:inline;}
65
+ input:checked+.box label span:nth-child(2){display:none;}
66
+ ```
67
+ ```HTML
68
+ <input type="checkbox" id="dsp1" checked class="switch">
69
+ <div class="box">
70
+ <ul class="list">
71
+ <li>1件目の記事</li>
72
+ <li>2件目の記事</li>
73
+ <li>3件目の記事</li>
74
+ <li>4件目の記事</li>
75
+ <li>5件目の記事</li>
76
+ <li>6件目の記事</li>
77
+ <li>7件目の記事</li>
78
+ <li>8件目の記事</li>
79
+ <li>9件目の記事</li>
80
+ <li>10件目の記事</li>
81
+ </ul>
82
+ <label for="dsp1">
83
+ <span>もっと見る</span>
84
+ <span>閉じる</span>
85
+ </label>
86
+ </div>
87
+ <input type="checkbox" id="dsp2" checked class="switch">
88
+ <div class="box">
89
+ <ul class="list">
90
+ <li>1件目の記事</li>
91
+ <li>2件目の記事</li>
92
+ <li>3件目の記事</li>
93
+ <li>4件目の記事</li>
94
+ <li>5件目の記事</li>
95
+ <li>6件目の記事</li>
96
+ <li>7件目の記事</li>
97
+ <li>8件目の記事</li>
98
+ <li>9件目の記事</li>
99
+ <li>10件目の記事</li>
100
+ </ul>
101
+ <label for="dsp2">
102
+ <span>もっと見る</span>
103
+ <span>閉じる</span>
104
+ </label>
105
+ </div>
56
106
  ```