在页面加载时,折叠应该是collapsed...but的,在页面加载时,它被展开了,我不知道如何修复这个错误?
$(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;
});这是我的代码的jsFiddle example。
发布于 2012-11-19 00:14:42
从您的示例中删除以下代码部分,它将按您预期的方式工作:
//Open The First Accordion Section When Page Loads
$('.accordion-header').first().toggleClass('active-header').toggleClass('inactive-header');
$('.accordion-content').first().slideDown().toggleClass('open-content');jsFiddle Working Example
发布于 2012-11-19 00:08:51
对我来说,只需将display: none添加到accordion-content div中似乎就可以做到这一点:
$('.accordion-content').css({'width' : contentwidth }).css('display':'none');这是一个实际操作的演示:http://jsfiddle.net/YsY7n/1/
https://stackoverflow.com/questions/13441790
复制相似问题