jquery实现简单手风琴菜单效果实例
本文实例讲述了jquery实现简单手风琴菜单效果的方法。分享给大家供大家参考。具体实现方法如下:
(function($){ varallPanels=$('.accordion>dd').hide(); $('.accordion>dt>a').click(function(){ allPanels.slideUp(); $(this).parent().next().slideDown(); returnfalse; }); })(jQuery);
HTML代码:
<dlclass="accordion"> <dt><ahref="">Panel1</a></dt> <dd>Pellentesquefermentumdolor.Aliquamquamlectus,facilisisauctor,ultricesut,elementumvulputate,nunc.</dd> <dt><ahref="">Panel2</a></dt> <dd>Donecnecjustoegetfelisfacilisisfermentum.Aliquamporttitormaurissitametorci.Aeneandignissimpellentesquefelis.</dd> <dt><ahref="">Panel3</a></dt> <dd>Loremipsumdolorsitamet,consectetueradipiscingelit.Phasellushendrerit.Pellentesquealiquetnibhnecurna.Innisineque,aliquetvel,dapibusid,mattisvel,nisi.Sedpretium,ligulasollicitudinlaoreetviverra,tortorliberosodalesleo,egetblanditnunctortoreunibh.Nullammollis.Utjusto.Suspendissepotenti.</dd> </dl>
SCSS部分:
/*Sorryifyoudon'tuseSASS.Shouldbeprettyeasytoconvert.*/ .accordion{ margin:50px; dt,dd{ padding:10px; border:1pxsolidblack; border-bottom:0; &:last-of-type{ border-bottom:1pxsolidblack; } a{ display:block; color:black; font-weight:bold; } } dd{ border-top:0; font-size:12px; &:last-of-type{ border-top:1pxsolidwhite; position:relative; top:-1px; } } }
希望本文所述对大家的jQuery程序设计有所帮助。