すでに動作するはずですが何をしています。 jQueryので
、要素のスタイル属性が最初show
が呼び出されるnone
、以外の何か他のものに設定display
ていない限り、それがないすべての表示のためのスタイル属性を削除しています。ブロックを設定しません。
this fiddleでボタンをクリックすると、CSSに設定されているdisplay
が要素に設定されていることが分かります。
ここでは、関連するコードがjQuery sourceにあります:
function showHide(elements, show) {
var display, elem, hidden,
values = [],
index = 0,
length = elements.length;
for (; index < length; index++) {
elem = elements[ index ];
if (!elem.style) {
continue;
}
values[ index ] = data_priv.get(elem, "olddisplay");
display = elem.style.display;
if (show) {
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if (!values[ index ] && display === "none") {
elem.style.display = "";
}
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if (elem.style.display === "" && isHidden(elem)) {
values[ index ] = data_priv.access(elem, "olddisplay", css_defaultDisplay(elem.nodeName));
}
} else {
if (!values[ index ]) {
hidden = isHidden(elem);
if (display && display !== "none" || !hidden) {
data_priv.set(elem, "olddisplay", hidden ? display : jQuery.css(elem, "display"));
}
}
}
}
// Set the display of most of the elements in a second loop
// to avoid the constant reflow
for (index = 0; index < length; index++) {
elem = elements[ index ];
if (!elem.style) {
continue;
}
if (!show || elem.style.display === "none" || elem.style.display === "") {
elem.style.display = show ? values[ index ] || "" : "none";
}
}
return elements;
}
私がチェックするための以下の情報があるので、クラスをトグルすると、通常は一般的に速くなることに注意してください。
あなたは 'ディスプレイの間にそれを変更するクラス名を切り替えることができます:十分な –