私は jQuery の折りたたみ可能なパネルを作成しようとしていますが、そのためのプラグインはありますが、私が望んでいることを正確に実行するプラグインが見つかりませんでした。ほとんどの場合は機能しますが、機能しないビットが 1 つあります。その理由はわかりません。
(例のページはhttp://www.thekmz.co.uk/misc/cpanel/index1.htmlにあります)
それがどのように機能するか(または場合によっては機能しない可能性があります)
HTML
<div id="container">
<div class="collapsiblePanel" title="Example Collapsible Panel">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit... etc</p>
</div>
</div>
Javascript
(function($) {
$.fn.extend({
collapsiblePanel: function() {
return $(this).each(initCollapsiblePanel);
}
});
})(jQuery);
function initCollapsiblePanel() {
if ($(this).children().length == 0) {
$(this).wrapInner("<div></div>");
}
$(this).children().wrapAll("<div class='cpanelContent'></div>");
$("<div class='cpanelTitle'><div>" + $(this).attr("title") + "</div><div class='cpanelToggle'>more</div></div>").prependTo($(this));
$(".cpanelContent", this).hide();
$(".cpanelTitle", this).click(toggleCollapsiblePanel);
}
function toggleCollapsiblePanel() {
$(".cpanelContent", $(this).parent()).slideToggle();
if ($(".cpanelContent", $(this).parent()).is(":hidden")) {
$(".cpanelToggle", this).html('more');
} else {
$(".cpanelToggle", this).html('close');
}
}
CSS
#container {
width:300px;
height:300px;
}
.collapsiblePanel {
width:100%;
}
.cpanelTitle {
position:relative;
width:100%;
cursor: pointer;
cursor: hand;
}
.cpanelToggle {
position:absolute;
top:0px;
right:0px;
font-style:italic;
}
そのため、クラス collapsiblePanel を持つ div を取り、さまざまなネストされた div を作成します。ヘッダーの div には、タイトルと、コンテンツ パネルが展開されているか折りたたまれているかによって、「詳細」または「閉じる」となる右にフロートされるいくつかのトグル テキストが保持されます。
動作しないビットは、
if ($(".cpanelContent", $(this).parent()).is(":hidden")) {
toggleCollapsiblePanel() 関数で。div は問題なく切り替えられるので、コンテンツ div を選択しているようですが、同じものを使用して非表示かどうかを確認すると (cPanelToggleDiv のテキストを変更できます)、常に false として返されます。私はそれを正しくやっていません。
何が起こっているのかを確認するために (上記のリンクの例のページで) そこに大量のコンソール呼び出しを入れましたが、それを見ることができません。
私の絶望/混乱を指摘する助けがあれば大歓迎です.
よろしくナイモア