在垂直手风琴菜单中,我想用其他菜单或分区替换菜单内容。这是我的代码
<nav>
<ul id="nav">
<li><a href="#">Menu 1</a>
<div> New Menu 1</div>
<ul>
After clicking on each header we will show/hide the internal navigation links. This situation can get tricky when trying to implement sub-navigation and sub-sub-navigation if you want to show/hide those as well. A better solution is to nest a third element which is also displayed immediately with all the other links, but rendered using additional padding.
</ul>
</li>
<li><a href="#">Menu 2</a>
<div> New Menu 2</div>
<ul>
Create html drop down menus for web page navigation in a few clicks! Define text, font, color, URL and more for the multilevel dropdown menus. You don't need to write any code by yourself. Horizontal drop down menus builder will generate it for you. You can preview menus in web browser without quitting the program. Css drop down menus render perfectly in Firefox, Safari and Chrome. Html drop down menus also works on non-CSS3 compitable browsers
</ul>
</li>
<li><a href="#">Menu 3</a>
<div> New Menu 3</div>
<ul>
PURE CSS Menu Maker is a free and powerful graphical user interface for creating 100% pure CSS web menus. CSS menus do not require JavaScript or plug-ins in order to run. PURE CSS Menu Maker can create horizontal as well as vertical menus. Menus generated with PURE CSS Menu Maker may be modified freely, either with PURE CSS Menu Maker or by hand.
</ul>
</li>
</ul>
</nav>
脚本
$(document).ready(function()
{
$('#nav > li > ul:eq(0)').show();
$("#nav > li > a").on("click", function(e)
{
if($(this).parent().has("ul"))
{
e.preventDefault();
}
if(!$(this).hasClass("open"))
{
// hide any open menus and remove all other classes
$("#nav li ul").slideUp(350);
$("#nav li a").removeClass("open");
// open our new menu and add the open class
$(this).next("ul").slideDown(350);
$(this).addClass("open");
}
else if($(this).hasClass("open")) {
$(this).removeClass("open");
$(this).next("ul").slideUp(350);
}
});
});
点击我想用div更改菜单并在下一个菜单上隐藏该div。它怎么做?感谢。
这是一个小提琴: http://jsfiddle.net/sW96K/答案 0 :(得分:0)
您可以尝试使用简单的slideToggle()
$(document).ready(function()
{
$('#nav > li > ul:eq(0)').show();
$("#nav li a").on("click", function(e)
{
$(this).siblings("ul").slideToggle(350);
});
});
检查这个小提琴:http://jsfiddle.net/Kritika/ZXE6K/
此代码将打开一个菜单onclick但它不会关闭其他打开的菜单。这是简单的隐藏/显示
div
答案 1 :(得分:0)
你想要这样吗?小脚本可以处理这个问题。 DEMO http://jsfiddle.net/yeyene/HmwN8/3/
$(document).ready(function(){
$('a.toggle').on('click', function(){
$('.content').slideUp('2000', "easeOutBounce");
if($('div#'+$(this).attr('rel')).css('display')=='block')
$('div#'+$(this).attr('rel')).slideUp('2000', "easeOutBounce");
else
$('div#'+$(this).attr('rel')).slideDown('2000', "easeOutBounce");
});
});
答案 2 :(得分:0)
我想我明白你的意思现在......它应该是这样的:
编辑:每当你更换内容时,它就会用一个函数简单地重新实例化。
function doit(element) {
$(element).on("click", function (e) {
e.preventDefault();
var newElement = $(element).next();
$(element).parent().siblings().each(function(){
if(!$(this).children('a').is(':visible')){
$(this).children('div').clone().hide().insertAfter($(this).children('a'));
$(this).children('div:first-child').replaceWith($(this).children('a').show());
$(this).children('ul').hide(350);
doit($(this).children('a'));
}
});
$(element).clone().hide().insertAfter($(element).next());
$(element).replaceWith($(element).next().show());
$(newElement).next().next().slideToggle(350); // slide toggle in 350ms
doit(newElement);
});
}
$(document).ready(function () {
$('#nav > li > ul').hide(); // Hide all menus
$('#nav > li > div').hide(); // Hide all divs under menus
$("#nav > li > a").each(function() {
doit(this);
});
$('#nav > li:first-child > a').click(); // Open first element
});
答案 3 :(得分:0)
请参阅以下链接。您可以找到不同类型的Accordions
http://jqueryui.com/accordion/