简体   繁体   English

从同一页面和外部页面上的锚点链接打开手风琴面板

[英]Opening an Accordion Panel from anchor link on same page and external page

I have an Accordion as per markup, CSS and jquery for the same as given. 我有一个手风琴作为标记,CSS和jquery与给定的相同。 I could not establish an external anchor link (same page and other pages) to trigger open the specific panel. 我无法建立外部锚链接(同一页面和其他页面)来触发打开特定面板。 The Accordion is from a template. 手风琴来自一个模板。

HTML 的HTML

<!-- Accordions -->
<h1 class="h-margin">Accordions</h1>
<div class="accordion-trigger">Categories</div>     
<div class="accordion-container" data-panel="0">
    Pellentesque habitant 
</div>     

<div class="accordion-trigger">Categories</div> 
<div class="accordion-container" data-panel="1">
    Pellentesque habitant morbi 
</div>

<div class="accordion-trigger">Categories</div>         
<div class="accordion-container" data-panel="2">
    Pellentesque habitant morbi tris
</div>
<!-- ENDS Accordions -->

<a href="#">Open Section 1</a>

<a href="#">Open Section 2</a>

<a href="#">Open Section 3</a>

JavaScript 的JavaScript

// Accordion box
$('.accordion-container').hide(); 
$('.accordion-trigger:first').addClass('active').next().show();
$('.accordion-trigger').click(function(){
    if( $(this).next().is(':hidden') ) { 
        $('.accordion-trigger').removeClass('active').next().slideUp();
        $(this).toggleClass('active').next().slideDown();
    }
    return false;
});

It will help you: 它将帮助您:

 // open content that matches the hash
 var hash = window.location.hash;
 var thash = hash.substring(hash.lastIndexOf('#'), hash.length);
 $('.accordion').find('a[href*='+ thash + ']').closest('h3').trigger('click');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM