关闭手风琴菜单的所有选项卡
Keep all tabs of accordion menu closed
我的存档中有一个简单的手风琴菜单,第一个菜单项始终打开,但我如何修改 JS 以便在页面加载时关闭所有菜单项? URL 是 http://helloarchie.blue/archives
JS
function openFirstPanel(){
$('.accordion > dt:first-child').next().addClass('active').slideDown();
}
(function($) {
var allPanels = $('.accordion > dd').hide();
openFirstPanel();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});
Setting active to false will collapse all panels. This requires the collapsible option to be true.
http://api.jqueryui.com/accordion/
$('.accordion').accordion({
active: false,
collapsible: true
});
删除 openFirstPanel()
函数和函数调用。
所以你得到这个:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});
我的存档中有一个简单的手风琴菜单,第一个菜单项始终打开,但我如何修改 JS 以便在页面加载时关闭所有菜单项? URL 是 http://helloarchie.blue/archives
JS
function openFirstPanel(){
$('.accordion > dt:first-child').next().addClass('active').slideDown();
}
(function($) {
var allPanels = $('.accordion > dd').hide();
openFirstPanel();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});
Setting active to false will collapse all panels. This requires the collapsible option to be true. http://api.jqueryui.com/accordion/
$('.accordion').accordion({
active: false,
collapsible: true
});
删除 openFirstPanel()
函数和函数调用。
所以你得到这个:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});