简体   繁体   English

更改手风琴折叠时的图标方向

[英]Change Icon Direction on Accordion Collapse

I have this JSFiddle which includes a Bootstrap Accordion embedded inside another Accordion, the issue is that the Chevron to the right does not now behave as expected. 我有这个JSFiddle ,它的另一个手风琴中嵌入了一个Bootstrap手风琴,问题是右边的Chevron现在不能像预期的那样工作。

As you can see by the code below, the chevron changes direction when collapse is triggered, however, now it is in an embedded accordion this doesn't appear to be the solution. 从下面的代码中可以看到,人字形在触发collapse会改变方向,但是,现在在嵌入式手风琴中,这似乎不是解决方案。

$('.collapse').on('shown.bs.collapse', function(){
$(this).parent().find(".glyphicon-chevron-down").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
}).on('hidden.bs.collapse', function(){
$(this).parent().find(".glyphicon-chevron-up").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
});

I usually prefer to do this with CSS - less messy than trying to detect which item opened/closed when you are nesting, or have multiple on a page. 我通常更喜欢使用CSS进行操作-比尝试检测嵌套时打开或关闭的项或页面上有多个项的混乱程度要小。

1) Add the class 'collapsed' to your accordion headings if they are closed by default (bootstrap toggles this class, but if you don't have it present when the page loads, it doesn't get added until you open and then close an accordion item). 1)如果默认情况下关闭了“折叠”类,则将其添加到您的手风琴标题中(引导程序会切换该类,但是如果在页面加载时不显示该类,那么直到您打开然后关闭该类才会被添加手风琴项目)。

2) Get rid of the JS and add this CSS: 2)摆脱JS并添加以下CSS:

.panel-heading.collapsed .glyphicon-chevron-down {
  transform:rotateX(0deg);
}
.panel-heading .glyphicon-chevron-down {
  transition:transform .5s;
  transform:rotateX(180deg);
}

If you don't like the flip animation, just get rid of the transition rule, but I like to think it adds a little something. 如果您不喜欢翻转动画,请摆脱transition规则,但我想它会增加一些东西。

http://jsfiddle.net/rr7oggLv/6/ http://jsfiddle.net/rr7oggLv/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM