LoginSignup
0
1

More than 1 year has passed since last update.

jqueryを使用したシンプルな「もっと見る」ボタンの実装

Last updated at Posted at 2022-04-11

実装したもの

See the Pen Untitled by yoshida (@yoshi090) on CodePen.

シンプルな箇所

・「.c5-banner__content」のdivを加えるだけでコンテンツを追加できる。わざわざ「もっと見る」部分のコンテナを作成する必要がない。

index.html
<div class="c5-banner__content">
  <p>Content 1</p>
</div>

・「もっと見る」部分のコンテナの数が設定した数より少なければ「もっと見る」ボタンが非表示になる。下はコンテナの数が4つ以上なら「もっと見る」ボタンを表示する。

page.js
morenum1 = 3;
if(contentNum1 > morenum1){
 //4つ目以降のコンテンツを隠す
 $('.js-banner1 .c5-banner__content:nth-child(n+' + (morenum1 + 1) + ')').addClass('js-more1').hide();
  moreContents(btn1,content1);
}else{
   //コンテンツが3つ以下ならボタンを隠す
   $(btn1).hide();
}

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1