シンプルなアコーディオンパネル「Simple Toggle」

シンプルなアコーディオンパネル「Simple Toggle」をご紹介。

Simple Toggle with CSS & jQuery

まずHTMLは以下のようになります。

Toggle Header

Content Header

そしてCSS。
h2.trigger {
	padding: 0 0 0 50px;
	margin: 0 0 5px 0;
	background: url(h2_trigger_a.gif) no-repeat;
	height: 46px;
	line-height: 46px;
	width: 450px;
	font-size: 2em;
	font-weight: normal;
	float: left;
}
h2.trigger a {
	color: #fff;
	text-decoration: none;
	display: block;
}
h2.trigger a:hover { color: #ccc; }
h2.active {background-position: left bottom;} /*--When toggle is triggered, it will shift the image to the bottom to show its "opened" state--*/
.toggle_container {
	margin: 0 0 5px;
	padding: 0;
	border-top: 1px solid #d6d6d6;
	background: #f0f0f0 url(toggle_block_stretch.gif) repeat-y left top;
	overflow: hidden;
	font-size: 1.2em;
	width: 500px;
	clear: both;
}
.toggle_container .block {
	padding: 20px; /*--Padding of Container--*/
	background: url(toggle_block_btm.gif) no-repeat left bottom; /*--Bottom rounded corners--*/
}

CSSは記述がちょっと長いので、
実際に使用する場合は、外部CSSとして読み込むと良いと思います。
そしてjQueryを使用するので当然以下のようにjQueryを読み込み、

そして下記スクリプトをhead内に記述します。
$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click
	$("h2.trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("h2.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});

})
サンプルが公開されており以下URLより確認できます。

http://www.sohtanaka.com/web-design/examples/toggle/

また少しCSSに手を加えてサンプルを作成してみたので、
こちらも参考にしていただけたらと思います。

Simple Toggleサンプル


このエントリーのトラックバックURL :
http://netkatuyou.chicappa.jp/mt/mt-tb.cgi/85

コメントする

サイト内検索



カテゴリー

購読する 購読する

個人的おススメ その他情報

Powered by Movable Type 5.01