jQueryには、ヘッダーを非表示にしてから表示する2つの関数があり、ボタンを交換して、ヘッダーが非表示のときに「ヘッダーを表示」ボタンが表示され、その逆も同様です。それらは次のとおりです。
$('#close_header').click(function() {
$('#header').animate({ top: '-=150px' }, 500);
$(this).toggle();
$('#open_header').toggle();
});
$('#open_header').click(function() {
$('#header').animate({ top: '+=150px' }, 500);
$(this).toggle();
$('#close_header').toggle();
});
一緒に行くマークアップは次のとおりです。
<img src="images/close.png" id="close_header" class="header_control fadein button">
<img src="images/open.png" id="open_header" class="header_control fadein button">
<div id="header">
*Header content.*
</div>
これらの 2 つの機能を 1 つにまとめて、簡潔さと効率性を高める方法はありますか?