【问题标题】:How to add + and - to accordion如何在手风琴上添加 + 和 -
【发布时间】:2021-05-03 17:18:55
【问题描述】:

我已经实现了一个基本的手风琴,我需要在手风琴上添加 + 和 -。

如果手风琴是打开的,那么'-'应该是'+'

这是尝试过的:

JS:

$('.info').find('.accordion-toggle').click(function () {
    //Expand or collapse this panel
    $(this).next().slideToggle('fast');
    //Hide the other panels
    $(".accordion-content").not($(this).next()).slideUp('fast');
}); 

Demo Link

【问题讨论】:

标签: javascript html jquery css


【解决方案1】:

可以如下使用css伪元素:

CSS:

.accordion-toggle::after {
  content:"+";
}
.accordion-toggle.open::after {
  content:"-";
}

JS:

$('.info').find('.accordion-toggle').click(function () {
  //Expand or collapse this panel
  $(this).toggleClass("open").next().slideToggle('fast');

  //Hide the other panels
  $(".accordion-toggle").not($(this)).removeClass("open");
  $(".accordion-content").not($(this).next()).slideUp('fast');
});

Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2012-02-07
    • 2011-05-26
    • 1970-01-01
    • 2014-04-10
    • 2022-06-27
    • 1970-01-01
    相关资源
    最近更新 更多