所有可折叠的元素都不应折叠。至少其中一项应保持未折叠状态。我想更改以下示例以满足我的需要。我将不胜感激任何帮助!
/*\Animate collapsible set;\*/
$(document).one("pagebeforechange", function () {
// animation speed;
var animationSpeed = 200;
function animateCollapsibleSet(elm) {
// can attach events only one time, otherwise we create infinity loop;
elm.one("expand", function () {
// hide the other collapsibles first;
$(this).parent().find(".ui-collapsible-content").not(".ui-collapsible-content-collapsed").trigger("collapse");
// animate show on collapsible;
$(this).find(".ui-collapsible-content").slideDown(animationSpeed, function () {
// trigger original event and attach the animation again;
animateCollapsibleSet($(this).parent().trigger("expand"));
});
// we do our own call to the original event;
return false;
}).one("collapse", function () {
// animate hide on collapsible;
$(this).find(".ui-collapsible-content").slideUp(animationSpeed, function () {
// trigger original event;
$(this).parent().trigger("collapse");
});
// we do our own call to the original event;
return false;
});
}
// init;
animateCollapsibleSet($("[data-role='collapsible-set'] > [data-role='collapsible']"));
});
这里是一个关于动画可折叠集的工作示例:http://jsfiddle.net/jerone/gsNzT/
最佳答案
所以您不想让所有元素都折叠起来?我会这样做: 捕获折叠事件,然后:
如果折叠项当前已展开 (
.attr('data-collapsed') == "true"
),则返回 false 并防止折叠如果折叠项当前没有展开,没关系,它会折叠,另一个项会展开
你可能会考虑检查这个:How do I restrict a collapsible item to stay expanded...
如果已经实现了这个方法,还要检查 jquery 移动文档
关于javascript - 将 Accordion 中的一项限制为未折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20407157/