- メニュー
- メニューの中身
- メニュー
- メニューの中身
- メニュー
- メニューの中身
- メニュー
- メニューの中身
- メニュー
- メニューの中身
/* リセットCSS */
* {
list-style: none;
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* アコーディオンメニュー全体のサイズ・位置 */
.accordion {
width: 100%;
max-width: 600px;
margin: 0 auto;
}
/* クリック領域 */
.accordion-title {
height: 50px;
border-bottom: 1px solid #fff;
background-color: #006400;
color: #fff;
text-align: center;
line-height: 50px;
cursor: pointer;
}
/* クリックしたら表示される領域 */
.accordion-detail {
display: none;
padding: 2em 1em;
background-color: #98FB98;
text-align: center;
}
$(function () {
$('.ac-parent').on('click', function () {
$(this).next().slideToggle();
});
});
See the Pen アコーディオンメニュー by 奥谷 晋司 (@itpyduhk-the-encoder) on CodePen.
/* リセットCSS */
* {
list-style: none;
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* アコーディオンメニュー全体のサイズ・位置 */
.accordion {
width: 100%;
max-width: 600px;
margin: 0 auto;
}
/* クリック領域 */
.accordion-title {
height: 50px;
border-bottom: 1px solid #fff;
background-color: #006400;
color: #fff;
text-align: center;
line-height: 50px;
cursor: pointer;
position: relative; /* 追加 */
}
/* 擬似要素で下三角形を作成 */
.accordion-title:after {
content: "";
display: inline-block;
position: absolute;
top: 45%;
right: 30px;
width: 10px;
height: 10px;
border-right: 3px solid #fff;
border-bottom: 3px solid #fff;
transform: translateY(-50%) rotate(45deg);
transition: .3s;
}
/* オープン時にopenクラスを付与 */
.accordion-title.open:after {
transform: rotate(225deg);
}
/* クリックしたら表示される領域 */
.accordion-detail {
display: none;
padding: 2em 1em;
background-color: #98FB98;
text-align: center;
}
$(function () {
$('.accordion-title').on('click', function () {
$(this).next().slideToggle();
//openクラスをつける
$(this).toggleClass("open");
//クリックされていないac-parentのopenクラスを取る
$('.accordion-title').not(this).removeClass('open');
// 一つ開くと他は閉じるように
$('.accordion-title').not($(this)).next('.accordion-detail').slideUp();
});
});
See the Pen Untitled by 奥谷 晋司 (@itpyduhk-the-encoder) on CodePen.
/* リセットCSS */
* {
list-style: none;
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* アコーディオンメニュー全体のサイズ・位置 */
.accordion {
width: 100%;
max-width: 600px;
margin: 0 auto;
}
/* クリック領域 */
.accordion-title {
height: 50px;
border-bottom: 1px solid #fff;
background-color: #006400;
color: #fff;
text-align: center;
line-height: 50px;
cursor: pointer;
position: relative; /* 追加 */
}
/* ①プラスの横線 */
.accordion-title:before {
content: "";
position: absolute;
top: 50%;
right: 8px;
width: 24px;
height: 2px;
background: #fff;
transform: translateY(-50%);
}
/* ②プラスの縦線 */
.accordion-title:after {
content: "";
position: absolute;
top: 50%;
/* 8px+12px-1px(幅2pxの半分) */
right: 19px;
width: 2px;
height: 24px;
background: #fff;
transform: translateY(-50%);
transition: .3s;
}
/* ③オープン時にopenクラスを付与(縦線を回転させて非表示に) */
.accordion-title.open:after {
top: 25%;
opacity: 0;
transform: rotate(90deg);
}
/* クリックしたら表示される領域 */
.accordion-detail {
display: none;
padding: 2em 1em;
background-color: #98FB98;
text-align: center;
}
$(function () {
$('.accordion-title').on('click', function () {
$(this).next().slideToggle();
//openクラスをつける
$(this).toggleClass("open");
//クリックされていないac-parentのopenクラスを取る
$('.accordion-title').not(this).removeClass('open');
// 一つ開くと他は閉じるように
$('.accordion-title').not($(this)).next('.accordion-detail').slideUp();
});
});
See the Pen Untitled by 奥谷 晋司 (@itpyduhk-the-encoder) on CodePen.