自定义jquery手风琴箭头

时间:2016-09-05 13:27:06

标签: javascript jquery html css

我发现很难在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 个答案:

答案 0 :(得分: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>