2016-09-05 166 views
0

我發現很難在Jquery手風琴中實現我的自定義圖標以覆蓋默認箭頭。自定義jquery手風琴箭頭

我已經創建了我的類(參見下文)

jQuery的

$(function() { 
    var icons = { 
     header: "iconClosed", // custom icon class 
     activeHeader: "iconOpen" // custom icon class 
    }; 
    $("#accordion").accordion({ 
     icons: icons, 
     heightStyle: "content" 
    }); 
    $('#accordion input[type="checkbox"]').click(function (e) { 
     e.stopPropagation(); 
    }); 
}); 

CSS

.ui-icon.iconOpen { 
    content: '\02795'; /* Unicode character for "plus" sign (+) */ 
    font-size: 13px; 
    color: #777; 
    float: right; 
    margin-left: 5px; 
} 
.ui-icon.iconClosed { 
    content: "\2796"; /* Unicode character for "minus" sign (-) */ 
} 

與Unicode的表現可是我有問題。 任何幫助表示讚賞,謝謝。

回答

1

content屬性用於與:before:after僞元素,所以我想你想要做的是這樣的事情

$(function() { 
 
      var icons = { 
 
       header: "iconClosed", // custom icon class 
 
       activeHeader: "iconOpen" // custom icon class 
 
      }; 
 
      $("#accordion") 
 
       .accordion({ 
 
        icons: icons, 
 
        heightStyle: "content" 
 
       }); 
 
      $('#accordion input[type="checkbox"]').click(function (e) { 
 
       e.stopPropagation(); 
 
      }); 
 
     });
.ui-icon.iconOpen:after { 
 
    content: '\02795'; /* Unicode character for "plus" sign (+) */ 
 
    font-size: 13px; 
 
    color: #777; 
 
    float: right; 
 
    margin-left: 5px; 
 
} 
 
.ui-icon.iconClosed:after { 
 
    content: "\2796"; /* Unicode character for "minus" sign (-) */ 
 
    font-size: 13px; 
 
    color: #777; 
 
    float: right; 
 
    margin-left: 5px; 
 
}
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 
<div id="accordion"> 
 
    <h3>Section 1</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>Section 2</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>Section 3</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>Section 4</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>