我使用bootstrap JavaScript库并使其工作崩溃/展开元素。代码如下所示:
<div id="e_ticket_info" class="e_ticket_font" runat="server" Visible="False">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" style="color:firebrick; font-size: large;">
E-TICKET...
</a>
<i class="icon-large icon-arrow-down"></i>
</h1>
</div>
<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
Some text...
</div>
</div>
</div>
</div>
</div>
如您所见,我能够显示向下箭头图标。当我单击accordion元素时,文本会向下展开我想要的内容,但是我需要在此时将箭头向下图标切换为向上箭头图标,反之亦然,当单击accordion元素以折叠文本以再次显示向下箭头图标时。 / p>
怎么做?
答案 0 :(得分:4)
<强> CSS 强>
/**
Created new class toggle arrow that uses the sprite
coordinates for the up and down arrows in bootstrap.
**/
.toggle-arrow{
background-position: -289px -96px;
}
/**
This specific selector will cause the toggling
bootstrap adds and removes the collapsed class on the accordian.
**/
.collapsed .toggle-arrow{
background-position: -312px -96px;
}
<强> HTML 强>
<!-- Nested the i tag within the a toggle by collapsed -->
<div class="panel-heading">
<h1 class="panel-title">
<!-- Initialized a with class="collapsed" -->
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"
style="color:firebrick; font-size: large;" class="collapsed">
E-TICKET...
<i class="icon-large toggle-arrow"></i>
</a>
</h1>
</div>
JS小提琴: http://jsfiddle.net/uBzeZ/1/
答案 1 :(得分:1)
凯文的回答非常好!关于他的答案的好处是,它也适用于Bootstrap 2,不像我发现的其他答案(例如Bootstrap 3 Collapse show state with Chevron icon)。
回答你的问题tesicg,Kevin Bowersox正在做的是一种css sprite技术,利用了bootstrap精灵。
查看http://css-tricks.com/css-sprites/以获取精彩工具的链接和精灵的解释。
我个人想要使用雪佛龙图标,所以我修改了凯文的答案:
/** Created new class toggle arrow that uses the sprite
coordinates for the up and down arrows in bootstrap. **/
.toggle-arrow{
background-position: -312px -116px;
}
/** This specific selector will cause the toggling
bootstrap adds and removes the collapsed class on the accordian. **/
.collapsed .toggle-arrow{
background-position: -454px -72px;
}
基本上,我所做的是移动“视口”像素,如果你愿意的话,露出精灵的V形部分,而不是向上/向下箭头。
我还添加了右拉类,以便图标位于手风琴标题的最右侧,如下所示:
<i class="icon-large toggle-arrow pull-right"></i>
谢谢Kevin,这帮了很多!