/ Published in: jQuery
Expand |
Embed | Plain Text
<!DOCTYPE html> <html> <head> <!-- <script class="jsbin" src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js"></script> --> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script class="jsbin" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <style> article, aside, figure, footer, header, hgroup, menu, nav, section { display: block; } h3 { margin: 0; padding: 10px 0;} /* ACCORDION STYLES */ .accordionSection { overflow: hidden; margin-bottom: 10px; border-radius: 3px; border: 1px solid #d5d5d5; } .accordionSection.open { background-color: #E5F6FF; } .accordionSection:hover { border-color: #C6E5F8; } .accordionTitle { margin: 0; padding: 5px 20px; cursor: pointer; color: #004FB6; /*background-image: url(../images/plus-minus.png);*/ background-image: url(http://localhost:3000/Content/css/../images/plus-minus.png); background-repeat: no-repeat; background-position: 97% -54px; } .accordionSection.open .accordionTitle{ background-position: 97% 11px; } .accordionTitle:hover { background-color: #E5F6FF; } .accordionTitle h3 { padding: 0; display: inline-block; min-width: 160px; margin-right: 20px; } .ie6 .accordionTitle h3 { min-width: 160px; width: auto; } .accordionContent { margin: 0; padding: 0 20px; } /* ACCORDION BEHAVIOURS */ /* Hide accordion content in closed sections */ .accordionSection.closed .accordionContent{ display: none; } /* Fix for parents & children */ .accordionSection.open .accordionSection.closed .accordionContent { display: none; } /* Show accordion content in open sections */ .accordionSection.open .accordionContent { display: block; } /* Fix for parents & children */ .accordionSection.closed .accordionSection.open .accordionContent{ display: block; } </style> </head> <body> <section class="accordionSection closed"> <div class="accordionTitle"> <h3>accordionTitle</h3> </div> <div class="accordionContent"> <h3>Accordion title</h3> <p>Just some content</p> </div> </section> <section class="accordionSection open"> <div class="accordionTitle"> <h3>accordionTitle</h3> </div> <div class="accordionContent"> <h3>Accordion title</h3> <p>Just some content</p> </div> </section> <section class="accordionSection closed"> <div class="accordionTitle"> <h3>accordionTitle</h3> </div> <div class="accordionContent"> <h3>Accordion title</h3> <p>Just some content</p> <section class="accordionSection closed"> <div class="accordionTitle"> <h3>accordionTitle</h3> </div> <div class="accordionContent"> <h3>Accordion title</h3> <p>Just some content</p> </div> </section> <section class="accordionSection closed"> <div class="accordionTitle"> <h3>accordionTitle</h3> </div> <div class="accordionContent"> <h3>Accordion title</h3> <p>Just some content</p> </div> </section> </div> </section> <script> $.fn.showAccordion = function() { } $(document).ready(function(){ $(".accordionTitle").click(function(event) { // Cache some shizzle var thisTitle = $(this); var thisContent = thisTitle.next(".accordionContent"); var thisParent = thisTitle.parent(".accordionSection"); var thisSiblings = thisParent.siblings(".accordionSection"); // Close sibling accordion sections thisSiblings.each(function(){ if ($(this).is(".open")) { $(this).switchClass("open", "closed"); $(this).children(".accordionContent").slideUp(150); } }); // Show this accordion section if (thisParent.is(".closed")) { thisParent.removeClass("closed").addClass("open"); thisContent.slideDown(150); } else { thisParent.removeClass("open").addClass("closed"); thisContent.slideUp(150); } }); }); </script> </body> </html>
You need to login to post a comment.
