Jquery手风琴定制点击事件

时间:2013-10-09 10:56:13

标签: javascript jquery html css jquery-ui

我正在使用Jquery accordion手风琴。问题是我想在用户点击加号或减号图标时显示和隐藏conent面板,但是它在标题点击时全部打开,而且toggles在标题部分的chrome和safari中无效,并且在内容部分工作帮助应该是apriciated。 enter image description here 代码 -

<?php
$cs=Yii::app()->clientScript;
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/jquery.min.js', CClientScript::POS_HEAD);
$cs->registerScriptFile('http://code.jquery.com/ui/1.10.3/jquery-ui.js', CClientScript::POS_HEAD);
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/toggles.min.js', CClientScript::POS_HEAD);
$cs->registerCssFile('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
$cs->registerCssFile(Yii::app()->baseUrl . '/css/themes/toggles-light.css');
$cs->registerCssFile(Yii::app()->baseUrl . '/css/toggles.css');

&GT;

的CSS -

 <style>
.ui-accordion-header {
    background:none;
}
.ui-accordion-content {
    background:none;
}
.iconOpen {
    background:url('<?php echo Yii::app()->request->baseUrl; ?>/img/minus.png') no-repeat !important;
    background-size:46px !important;
    width:46px;
    height:44px;
}
.iconClosed {
    background:url('<?php echo Yii::app()->request->baseUrl; ?>/img/plus.png') no-repeat !important;
    background-size:46px !important;
    width:46px;
    height:44px;
}
.ui-accordion .ui-accordion-header .ui-accordion-header-icon {
    top: 25%;
    left: 0.0em;
    margin-top: -12px;
}
.ui-accordion .ui-accordion-icons {
    padding-left: 4.2em;
}
.ui-accordion .ui-accordion-header {
    margin-top: 0px;
    height: 26px !important;
}
</style>

JS -

<script>
$(function() {
 var icons = {
         header: "iconClosed",    // custom icon class
         activeHeader: "iconOpen" // custom icon class
     };
$( "#main_accordion" ).accordion({
icons: icons,
collapsible: true,
heightStyle: "content"
});
$('.toggle').toggles({clicker:$('.clickme')});

});
</script>

HTML: -

<div id="main_accordion">
    <h3>R
      <div align="right" style=" margin-top: -16px;">
        <div class="toggle-light">
          <div class="toggle"></div>
        </div>
      </div>
    </h3>
    <div>
      <p>interface</p>
    </div>
    <h3>F
      <div align="right" style=" margin-top: -16px;">
        <div class="toggle-light">
          <div class="toggle"></div>
        </div>
      </div>
    </h3>
    <div>
      <p> Feed Back
      <div class="toggle-light">
        <div class="toggle"></div>
      </div>
      </p>
    </div>
  </div>

1 个答案:

答案 0 :(得分:6)

要将手风琴的打开/关闭限制为只有图标,您需要使用beforeActivate选项并检查点击源自何处。如果不是来自图标,则取消激活事件。

$( "#main_accordion" ).accordion({
    icons: icons,
    collapsible: true,
    heightStyle: "content",
    beforeActivate:function(event, ui ){
            var fromIcon = $(event.originalEvent.target).is('.ui-accordion-header > .ui-icon');
            return fromIcon;
        }
});

演示 http://jsfiddle.net/5Qfwc/


更新(OP添加了指向jsfiddle 的链接后切换为

对于滑块,您在容器align="right"上有一个属性div,该属性不是div元素的有效属性。

我刚将样式更改为float:right并删除了边距,现在所有浏览器都能正常使用..

演示 http://jsfiddle.net/PKe5X/1/