我有几个页面的链接链接到我的手风琴网格所在的特定页面。在页面加载时,我希望手风琴网格的目标部分自动为用户折叠。
例如:页面A和页面B.页面A是用户来自查看页面B上的内容的页面。页面B带有4个(例如1,2,3和4)部分的手风琴。如果用户点击从页面A到页面B的链接2,手风琴的数字2部分应该折叠以供用户查看。
在下面找到代码:
HTML:
<div id="accord_bar">
<ul id="accordion">
<li><a href="#recent" class="heading">Number 1 Header</a>
<ul id="recent"><li>Number 1</li></ul>
</li>
<li><a href="#popular" class="heading">Number 2 Header</a>
<ul id="recent"><li>Number 2</li></ul>
</li>
<li><a href="#categories" class="heading">Number 3 Header</a>
<ul id="recent"><li>Number 3</li></ul>
</li>
<li><a href="#archive" class="heading">Number 4 Header</a>
<ul id="recent"><li>Number 4</li></ul>
</li></ul></div>
HEAD代码中的Javascipt:
<script type="text/javascript">
$(document).ready(function() {
$('#accordion').accordion(
{active: "a.default", header: "a.heading"}
);
});
链接手风琴Jquery文件:
<script type="text/javascript" src="js/jquery-ui-accordion.js"></script>
我真的需要尽快解决这个问题,如果有人能提供帮助,我将非常感激......
答案 0 :(得分:0)
您可以使用jQuery构建自己的简单accorion,不需要ui。
使用eq()
方法将手风琴的特定部分折叠成这种简单的手风琴结构。
Here is jsFiddle with hover trigger.
<强> jQuery的:强>
$('.content').slideUp(100);
$('.content').eq(1).slideDown(600);
//for collapsing second part of an accordion
$('.panel').hover(function() {//open
var takeID = $(this).attr('id');//takes id from clicked ele
$('.content').stop(false,true).slideUp(600);
//used stop for prevent conflict
$('#'+takeID+'C').stop(false,true).slideDown(600);
///show's hovered ele's id macthed div
});
<强> HTML:强>
<div class="panel" id="panel1">panel1</div>
<div class="content" id="panel1C">content1</div>
<div class="panel" id="panel2">panel2</div>
<div class="content" id="panel2C">content2</div>
<div class="panel" id="panel3">panel3</div>
<div class="content" id="panel3C">content3</div>
Here is jsFiddle with click trigger and close button.
<强> jQuery的:强>
$('.content').slideUp(100);
$('.content').eq(1).slideDown(600);
//for collapsing second part of an accordion
$('.panel').click(function() {//open
var takeID = $(this).attr('id');//takes id from clicked ele
$('#'+takeID+'C').slideDown(600);//show's clicked ele's id macthed div
});
$('span').click(function() {//close
var takeID = $(this).attr('id').replace('Close','');//strip close from id
$('#'+takeID+'C').slideUp(600);//hide clicked close button's panel
});
<强> HTML:强>
<div class="panel" id="panel1">panel1</div>
<div class="content" id="panel1C">content1<span id="panel1Close">X</span></div>
<div class="panel" id="panel2">panel2</div>
<div class="content" id="panel2C">content2<span id="panel2Close">X</span></div>
<div class="panel" id="panel3">panel3</div>
<div class="content" id="panel3C">content3<span id="panel3Close">X</span></div>
注意:我之前回答过手风琴相关的答案: collapse and expand tabs jquery / simple accordion