[英]First accordion panel open
I can't seem to work out how to get my first accordion panel to open automatically. 我似乎无法解决如何使我的第一个手风琴面板自动打开的问题。 Problem is, I can't set it to active as it is displaying data with PHP from a database so if I set the div to "active-panel" it applies it to all the panels.
问题是,由于它正在使用PHP从数据库显示数据,因此无法将其设置为活动状态,因此,如果将div设置为“ active-panel”,则会将其应用于所有面板。 Any help would be great!
任何帮助将是巨大的! Just to clarify, I'm just trying to get the first one to open automatically.
为了澄清,我只是想让第一个自动打开。 Code:
码:
$('.panel-holder').click(function () {
$(this).closest('.accordion').find('.panel-holder').removeClass('active-panel');
$(this).addClass('active-panel');
PHP PHP
echo "<div class='panel-holder'>
<div class='panel-title'>". $results['job_title'] ."
<i class='icon arrow_carrot-down'></i>
</div>
<div class='panel-content'>
<p class='lead'>". $results['job_summary'] ."</p>
<p>". $results['job_description'] ."</p>
</div>
</div><!--end of individual accordian panel-->";
Just add the "active-panel" class to the first item in PHP only. 只需将“ active-panel”类添加到PHP中的第一项即可。 Are those generated in a loop?
那些是在循环中生成的吗? Just create a counter variable that increases in every run of the loop.
只需创建一个计数器变量,该变量在循环的每次运行中都会增加。 If this counter == 1 (or 0 if you want to start with 0 ;) ) add the css class to your markup.
如果此计数器== 1(或者如果要从0开始,则为0;),则将css类添加到标记中。
Ended up creating the following solution: 最终创建了以下解决方案:
$('.panel-holder').each(function () {
$(this).closest('.accordion').find('.panel-holder:first').addClass('active-panel');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.