手风琴打开时交换背景图像

时间:2015-11-17 11:40:30

标签: javascript jquery html css accordion

我的网站上有一个简单的手风琴:http://jsfiddle.net/s7wL0y1p/

手风琴打开时如何更改右侧的图像?如果可能,我想将其更改为不同大小的图形。



function close_accordion_section(source) {
        $(source).parent().find('.accordion-section-title').removeClass('active');
        $(source).parent().find('.accordion-section-content').slideUp(300).removeClass('open');
    }

    $('.accordion-section-title').click(function(e) {     
        if($(e.target).is('.active')) {
            close_accordion_section(e.target);
        }else {
            $(this).addClass('active');
            $(e.target).parent().find('.accordion-section-content').slideDown(300).addClass('open')
        }

        e.preventDefault();
    });

.accordion {
  overflow: hidden;
  margin-bottom: 40px;
}

.accordion-section {
  padding: 15px;
  border: 1px solid #d8d8d8;
  background: #fbfbfb;
}

.accordion-section-title {
  width: 100%;
  display: inline-block;
  background: url("http://placehold.it/50x50") top right no-repeat;
}

.accordion-section-title.active, .accordion-section-title:hover {
  text-decoration: none;
}

.accordion-section-content {
  padding: 15px 0;
  display: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="accordion">
    <div class="accordion-section">
        <a class="accordion-section-title" href="#accordion-1">More information</a>
    <div id="accordion-1" class="accordion-section-content">
        <p>Text.</p>
        <p>
    </div>
    </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

行。那很简单。我在我的active课程中添加了一个图形。

.accordion-section-title.active {
  text-decoration: none;
  background: url("http://placehold.it/150x20") top right no-repeat;
}