Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

【Query】要素のフェードイン・フェードアウト

toggleメソッドで表示/非表示を切り替える

ソースコード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<input id="animate" type="button" value="Animate" />
<div class="box" style="height:40px;width:50;border:1px solid #000000"></div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<script type="text/javascript">
(function ($) {
	$(document).ready(function () {
		$('#animate').click(function () {
			// 「box」のclassが指定された要素の表示/非表示を切り替える
			$('.box').toggle();
		});
	});
})(jQuery);
</script>
</html>
初期表示


1回目のボタンクリック


2回目のボタンクリック


animateメソッドでフェードイン・フェードアウトさせる

ソースコード
<script type="text/javascript">
(function ($) {
	$(document).ready(function () {
		$('#animate').click(function () {
			// styleのopacityを徐々に切り替える
			$('.box').animate({ opacity : 'toggle' }, 'slow');
		});
	});
})(jQuery);
</script>
ボタンクリックのたびにフェードイン・フェードアウトします

# ハードコピーはとれませんでした。