我有一个手风琴菜单,我无法弄清楚如何链接。菜单本身工作正常。
当我点击下面的链接时,我的第一个手风琴菜单应该打开
<a href="case_studies.html#case1">Case study 1</a>
手风琴的JavaScript
<script type="text/javascript">
$(document).ready(function(){
$("a#show-panel").click(function(){
$("#lightbox, #lightbox-panel").fadeIn(300);
})
$("a#close-panel").click(function(){
$("#lightbox, #lightbox-panel").fadeOut(300);
})
})
</script>
<script type="text/javascript">
$(function(){
$("#accordion-header").accordion({ navigation: true });
});
</script>
accordion.js文件
$(document).ready(function()
{
//Add Inactive Class To All Accordion Headers
$('.accordion-header').toggleClass('inactive-header');
//Set The Accordion Content Width
var contentwidth = $('.accordion-header').width();
$('.accordion-content').css({'width' : contentwidth });
/* //Open The First Accordion Section When Page Loads
$('.accordion-header').first().toggleClass('active-header').toggleClass('inactive-header');
$('.accordion-content').first().slideDown().toggleClass('open-content'); */
// The Accordion Effect
$('.accordion-header').click(function () {
if($(this).is('.inactive-header')) {
$('.active-header').toggleClass('active-header').toggleClass('inactive-header').next().slideToggle().toggleClass('open-content');
$(this).toggleClass('active-header').toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
}
else {
$(this).toggleClass('active-header').toggleClass('inactive-header');
$(this).next().slideToggle().toggleClass('open-content');
}
});
return false;
});
手风琴的身体代码是
<div id="accordion-container">
<p class="accordion-header" style="border-top:solid 1px #009edb; border-bottom:solid 1px #009edb;"><span style="padding-left:10px; color:#009edb; padding-top:10px; line-height:25px;"><a href="#case1">Case study 1</a></span></p>
<div class="accordion-content">
<div class="textInner">
TEST TEXT THAT FALLS UNDER THE MENU
</div>
</div>
<p class="accordion-header" style="border-top:solid 1px #009edb; border-bottom:solid 1px #009edb;"><span style="padding-left:10px; color:#009edb; padding-top:10px; line-height:25px;"><a href="#case2">Case study 2</a></span></p>
<div class="accordion-content">
<div class="textInner">
TEST TEXT THAT FALLS UNDER THE MENU
</div>
</div>
</div>
感谢任何帮助。我在这里没有想法。
提前干杯谢谢, ģ
答案 0 :(得分:0)
$(function(){
$("#accordion-header").accordion({ navigation: true });
$("[href='#case1']").parent('.accordion-header').click();
});
(我让你自己找出如何从url获取哈希值)
编辑:查看你的代码,在你的手风琴插件中使用哈希变更处理程序事件(而不是点击事件)也可能更相关
答案 1 :(得分:0)
小提琴here! 正如我从你的问题中所理解的,这是有效的。
<li class="dropdown">
<a id="drop4" role="button" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4">
<li role="presentation"><a class= "opener" data-panel="0" role="menuitem" tabindex="-1" href="#">Bank</a></li>
<li role="presentation"><a role="menuitem"class= "opener" data-panel="1" tabindex="-1" href="#">Cash</a></li>
<li role="presentation"><a role="menuitem" class= "opener" data-panel="2" tabindex="-1" href="#">Property</a></li>
</ul>
</li>
<div id="Accordion">
<h3>Section 1</h3>
<div>
<p></p>
</div>
<h3>Section 2</h3>
<div>
<p></p>
</div>
<h3>Section 3</h3>
<div>
<p></p>
</div>
<h3>Section 4</h3>
<div>
<p>One</p>
<p>Two</p>
</div>
它的javascript是:
var $accordion = $("#Accordion");
$accordion.accordion();
$(".opener").on("click", function () {
var $this = $(this),
toOpen = $this.data("panel");
$accordion.accordion("option", "active", toOpen);
return false;
});