javascript - 将 Accordion 中的一项限制为未折叠

标签 javascript jquery html css jquery-mobile

所有可折叠的元素都不应折叠。至少其中一项应保持未折叠状态。我想更改以下示例以满足我的需要。我将不胜感激任何帮助!

/*\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/

最佳答案

所以您不想让所有元素都折叠起来?我会这样做: 捕获折叠事件,然后:

  1. 如果折叠项当前已展开 (.attr('data-collapsed') == "true"),则返回 false 并防止折叠

  2. 如果折叠项当前没有展开,没关系,它会折叠,另一个项会展开

你可能会考虑检查这个:How do I restrict a collapsible item to stay expanded...

如果已经实现了这个方法,还要检查 jquery 移动文档

关于javascript - 将 Accordion 中的一项限制为未折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20407157/

相关文章:

javascript - 如何在 JavaScript 中调用 Less.js 函数?

javascript - 连接两个字符串数组的元素 jQuery

jquery - 将 ctx.strokeStyle 与 ctx.fillStyle 一起使用

用于根据提供的值生成选择标签的 Javascript 辅助方法

html - 如果滚动高度至少为某个值,则显示背景图像

javascript - JS/JQuery - 获取复选框值时出现问题

javascript - vue中的v-bind是什么

javascript - 如果点击取消按钮,如何拒绝输入框中的任何更改?

javascript - ng-click 不打开新窗口

javascript - ES6 使用生成器函数对列表进行分区