|
Sunday, July 7th, 2024
Accordions javascript closed type
JavaScriptを使用してコンテンツ領域を開閉するアコーディオン機能を実装します。
ご自由にご利用ください。
Previews
Section 1
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Section 2
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Section 3
Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.
Examples html
<!-- accordion -->
<div class="accordion">
<article>
<div class="switch switch1">Section 1</div>
<section class="content1">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
<article>
<div class="switch switch2">Section 2</div>
<section class="content2">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
<article>
<div class="switch switch3">Section 3</div>
<section class="content3">
<div class="description">Implement accordion functionality. Accordions are useful when you want to toggle between hiding and showing large amount of content.</div>
</section>
</article>
</div>
<!-- /accordion -->
Examples css
/* - accordion - */
.accordion {
width: 100%;
height: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
}
article {
width: 100%;
height: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
}
.switch {
width: 100%;
min-height: 50px;
margin: 0px 0px 0px 0px;
padding: 10px 10px 10px 10px;
background-color: rgba(0, 0, 0, 0.0);
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-justify-content: space-between;
justify-content: space-between;
-webkit-align-content: center;
align-content: center;
-webkit-align-items: center;
align-items: center;
cursor: pointer;
}
.switch1 {
border: 1px solid rgba(0, 0, 0, 1.0);
}
.switch2 {
margin: -1px 0px 0px 0px;
border: 1px solid rgba(0, 0, 0, 1.0);
}
.switch3 {
margin: -1px 0px 0px 0px;
border: 1px solid rgba(0, 0, 0, 1.0);
}
.switch {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
.switch1::after,
.switch2::after,
.switch3::after {
content: "+";
}
.switch1::after,
.switch2::after,
.switch3::after {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
.switch1.open::after,
.switch2.open::after,
.switch3.open::after {
content: "-";
}
.switch1.open::after,
.switch2.open::after,
.switch3.open::after {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
section.content1,
section.content2,
section.content3 {
display: none;
}
section.content1 {
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
section.content2 {
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
section.content3 {
border-right: 1px solid rgba(0, 0, 0, 1.0);
border-bottom: 1px solid rgba(0, 0, 0, 1.0);
border-left: 1px solid rgba(0, 0, 0, 1.0);
}
.description,
.description,
.description {
width: 100%;
min-height: 100px;
margin: 0px 0px 0px 0px;
padding: 10px 10px 10px 10px;
background-color: rgba(0, 0, 0, 0.0);
}
.description,
.description,
.description {
font-family: sans-serif;
font-size: 1.4rem;
font-style: normal;
font-weight: 200;
text-decoration: none;
color: rgba(0, 0, 0, 1.0);
}
/* - /accordion - */
Examples javascript
// Add functionality to open and close content areas.(コンテンツ領域を開閉するための機能を追加します。)
$( function() {
$('.switch').on( 'click', function() {
// Content area animation time(コンテンツ領域のアニメーションの時間:300 = 0.3秒)
$(this).next().slideToggle(300);
// Icon area animation time(アイコン領域のアニメーションの時間:300 = 0.3秒)
$(this).toggleClass('open', 300);
} );
} );
Summary
最後までご高覧いただきましてありがとうございました。
JavaScriptを使用してコンテンツ領域を開閉するアコーディオン機能をご紹介させていただきました。
必要に応じて各コードを変更してご自由にご利用ください。
現場からは以上でした。