繁体   English   中英

Anchor Link-在其他站点上打开手风琴

[英]Anchor Link - Open accordion on other site

我有一个手风琴网站。 现在,当我在链接上单击我的起始站点时,该链接是指向具有锚点的另一个站点的链接,我想打开此特定的手风琴。 我解释一下工作流程:

  1. 我单击主页上的链接。 /news/#example1
  2. 新闻站点将打开,并滚动到已关闭的example1 id。
  3. ID为example1的手风琴条目应打开。

正如Mathias所说,您必须从URL中获取哈希值。 但是,如果您已经为ID为“ example1”的元素设置了手风琴jquery插件,则必须在URL上的哈希值触发该元素。

例:

如果html是:

<div id="example1"> <div class="accordion-header">Some title here for the content</div> <div class="accordion-content">The actual content of the accordion</div> </div>

然后,您必须这样做:

var hash = window.location.hash; 
if(hash == "#example1")
$('#example1').find('.accordion-header').trigger('click');

如果每个新闻内容都有自己的ID,则可以执行以下操作:

var hash = window.location.hash; 
$(hash).find('.accordion-header').trigger('click');
  1. 您可以使用以下代码从URL中获取哈希值。
  2. 编写一个脚本来打开手​​风琴( li ?)

var hash = window.location.hash; $( '#' +哈希).show();

暂无
暂无

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

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