簡體   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