3

我正在使用Jquery 手风琴制作手风琴。问题是,当用户单击加号或减号图标时,我想显示和隐藏内容面板,但它在标题单击时全部打开,并且切换在标题部分中的 chrome 和 safari 中不起作用,并且在内容部分工作任何帮助都应该得到解决. 在此处输入图像描述 代码-

<?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');

?>

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>
4

1 回答 1

8

要将手风琴的打开/关闭仅限于图标,您需要使用该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"在 container 上有一个属性div,这不是div元素的有效属性。

我只是将样式更改为float:right并删除了边距,现在它在所有浏览器上都可以正常工作..

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

于 2013-10-09T11:29:00.963 回答