更改手风琴箭头位置

时间:2014-09-09 06:57:50

标签: javascript css jquery-mobile

我是jquery Mobile的新手。我创建了一个手风琴,但我希望它上面的箭头显示在右侧。 任何人都可以帮助我吗?

以下是我的代码。

<div class="accordion" id = "accordion">

</div>

CSS

body {
    background-color: #333333;
    .accordion h3 a {
        width:50%
    }
    .accordion h3 a .ui-icon {
        float:right
    }
}

然后我加载了带数组的Accordion

for (i=0;i<names.length;i++)
  {               
      var newDiv = "<h3>"+names[i]+"</h3><p>"+subnames[i]+"</p>";
       $('.accordion').append(newDiv)
       $('.accordion').accordion("refresh");

}

3 个答案:

答案 0 :(得分:1)

在jQuery Mobile可折叠小部件中,您可以设置data-iconpos="right"将图标移到右侧:

    <div data-role="collapsibleset" data-theme="a" data-content-theme="a">
        <div data-role="collapsible" data-iconpos="right">
             <h3>Section 1</h3>

            <p>I'm the collapsible content for section 1</p>
        </div>
        <div data-role="collapsible" data-iconpos="right">
             <h3>Section 2</h3>

            <p>I'm the collapsible content for section 2</p>
        </div>
        <div data-role="collapsible" data-iconpos="right">
             <h3>Section 3</h3>

            <p>I'm the collapsible content for section 3</p>
        </div>
    </div>
  

这是 DEMO

对于动态添加的内容:

   var thedynamiccontent = '<div data-role="collapsible" data-iconpos="right"><h3>Another Section</h3><p>Hello from dynamic added section</p></div><div data-role="collapsible" data-iconpos="right"><h3>Another Section 2</h3><p>Hello from dynamic added section 2</p></div>'; 
   $("#accordion").append(thedynamiccontent).collapsibleset("refresh").enhanceWithin();
  

动态 DEMO

注意:您还可以更改使用的图标:data-collapsed-icon="arrow-r" data-expanded-icon="arrow-u"

答案 1 :(得分:0)

我觉得你得到的东西应该有用:

.accordion h3 a .ui-icon {
    float:right
}

请确保您在jQM-CSS之后执行或加载自定义CSS 。您也可以尝试!important语句:

.accordion h3 a .ui-icon {
    float:right !important;
}

答案 2 :(得分:0)

这对我有用。 https://forum.jquery.com/topic/accordion-icons-alignment

.ui-accordion .ui-accordion-header .ui-icon { 
    position: absolute; 
    left: 100%; 
    margin-left: -30px; 
    top: 50%; 
    margin-top: -8px; 
}
.ui-accordion-icons .ui-accordion-header a { 
    padding-left: 1em; 
}
相关问题