|

Tabs javascript

JavaScriptを使用してコンテンツ領域を切り替えるタブ機能を実装します。

ご自由にご利用ください。

Previews

Section 1
Section 2
Section 3
This is the first tab. Tabs are useful for showing or hiding large amounts of content.
This is the second tab. Tabs are useful for showing or hiding large amounts of content.
This is the third tab. Tabs are useful for showing or hiding large amounts of content.

Examples html

<!-- tab -->

<div class="tab">

	<div class="section">

		<section class="select1">Section 1</section>
		<section class="select2">Section 2</section>
		<section class="select3">Section 3</section>

	</div>

	<div class="container">

		<div class="content content1">
			<div class="description">This is the first tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

		<div class="content content2">
			<div class="description">This is the second tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

		<div class="content content3">
			<div class="description">This is the third tab. Tabs are useful for showing or hiding large amounts of content.</div>
		</div>

	</div>

</div>

<!-- /tab -->

Examples css

/* - tab - */

.tab {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
}

.section {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	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: flex-start;
	justify-content: flex-start;
	-webkit-align-content: flex-start;
	align-content: flex-start;
	-webkit-align-items: flex-start;
	align-items: flex-start;
}

section {
	width: -webkit-calc( ( 100% + 2px ) / 3 );
	width: calc( ( 100% + 2px ) / 3 );
	min-height: 50px;
	margin: 0px -1px 0px 0px;
	padding: 10px 10px 10px 10px;
	background-color: rgba(0, 0, 0, 0.8);
	border: 1px solid rgba(0, 0, 0, 0.8);
	display: -webkit-flex;
	display: flex;
	-webkit-flex-direction: column;
	flex-direction: column;
	-webkit-flex-wrap: wrap;
	flex-wrap: wrap;
	-webkit-justify-content: center;
	justify-content: center;
	-webkit-align-content: flex-start;
	align-content: flex-start;
	-webkit-align-items: flex-start;
	align-items: flex-start;
	cursor: pointer;
	transition: all .5s;
}

section {
	font-family: sans-serif;
	font-size: 1.4rem;
	font-style: normal;
	font-weight: 200;
	text-decoration: none;
	color: rgba(255, 255, 255, 1.0);
}

section:hover {
	color: rgba(255, 255, 255, 0.5);
}

section:active {
	color: rgba(255, 255, 255, 1.0);
}

section.select1 {
	background-color: rgba(255, 255, 255, 1.0);
	border-bottom: 0px solid rgba(0, 0, 0, 0.0);
	color: rgba(0, 0, 0, 1.0);
	cursor: auto;
}

.container {
	width: 100%;
	height: auto;
	margin: -1px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(255, 255, 255, 1.0);
	border: 1px solid rgba(0, 0, 0, 0.8);
}

.container .content {
	width: 100%;
	height: auto;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	background-color: rgba(0, 0, 0, 0.0);
}

.container .content2,
.container .content3 {
	display: none;
}

.description {
	width: 100%;
	min-height: 100px;
	margin: 1px 0px 0px 0px;
	padding: 10px 10px 10px 10px;
	background-color: rgba(0, 0, 0, 0.0);
}

.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);
}

/* - /tab - */

Examples javascript

// Add functionality to switch content areas.(コンテンツ領域を切り替えるための機能を追加します。)
$( function() {
	$('.section section').click( function() {
		var index = $('.section section').index(this);
		$('.container > div').css('display', 'none');
		// Animation Time(アニメーションの時間:300 = 0.3秒)
		$('.container > div').eq(index).fadeIn(300);
		$('.section section').removeClass('select1');
		$(this).addClass('select1');
	} );
} );

Summary

最後までご高覧いただきましてありがとうございました。

JavaScriptを使用してコンテンツ領域を切り替えるタブ機能をご紹介させていただきました。

必要に応じて各コードを変更してご自由にご利用ください。

現場からは以上でした。