每个标题中的JQuery手风琴不同的图标

时间:2011-04-08 15:17:28

标签: jquery jquery-ui-accordion

我正在尝试为我的页面创建一个Outlook风格的手风琴。我遇到的问题是找出如何为每个标题设置不同的图标。例)邮件标题的邮件图标,联系人标题的联系人图标。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:8)

这很容易做,只需要一点CSS。

<强> Demo

HTML

<div id="accordion"> 
    <h3 class="s1"><a href="#">Section 1</a></h3> 
    <div> 
        <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p> 
    </div> 
    <h3 class="s2"><a href="#">Section 2</a></h3> 
    <div> 
        <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p> 
    </div> 
    <h3 class="s3"><a href="#">Section 3</a></h3> 
    <div> 
        <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p> 
        <ul> 
            <li>List item one</li> 
            <li>List item two</li> 
            <li>List item three</li> 
        </ul> 
    </div> 
    <h3 class="s4"><a href="#">Section 4</a></h3> 
    <div> 
        <p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p> 
    </div> 
</div> 

CSS

.ui-accordion-header.s1 .ui-icon {
    background: url(http://p.yusukekamiyamane.com/icons/search/fugue/icons/table-join.png);
}
.ui-accordion-header.s2 .ui-icon {
    background: url(http://p.yusukekamiyamane.com/icons/search/fugue/icons/home-medium.png);
}
.ui-accordion-header.s3 .ui-icon {
    background: url(http://p.yusukekamiyamane.com/icons/search/fugue/icons/store-medium.png);
}
.ui-accordion-header.s4 .ui-icon {
    background: url(http://p.yusukekamiyamane.com/icons/search/fugue/icons/balloon-facebook-left.png);
}

的JavaScript

$(function() {
    $( "#accordion" ).accordion(); 
});