別ページから飛んできたときアコーディオンの指定の要素を開く

Facebook
Twitter

タイトルのまんまですが別ページからアンカーで飛んできたときに、アコーディオンの指定の要素を開きたいときありますよね。ないですか?僕は仕事でありましたよ。とりあえず以下サンプルを見ていただければと思います。

Elementorでそんな機能は今のところないのでjQueryで作りました。
まず次のようにページを作成します。
Aページ(Bページへ飛ぶリンクボタン)
Bページ(アコーディオンページ)

Aページ
<a href=”b.html#num1>1番目を開く</a>
<a href=”b.html#num2>2番目を開く</a>
<a href=”b.html#num3>3番目を開く</a>

Bページ
アコーディオンウィジェットを配置します。

そのウィジェットの下にHTMLウィジェットを入れます。

 

< script >
  //アコーディオンの場合
  jQuery(function () {
    var hash = location.hash;
    var tab = jQuery('.elementor-accordion-item');
    if (hash.length) {
      //ハッシュがあったら
      if (hash.match(/#num/)) {
        //番号
        var tabName = Number(hash.slice(4.1) - 1);
        //遅延
        jQuery('.elementor-accordion').delay(100).queue(function () {
          //上部タブ部分    
          tab.children('.elementor-tab-title').removeClass('elementor-active');
          tab.children('.elementor-tab-content').removeClass('elementor-active');
          tab.children('.elementor-tab-content').css('display', 'none');
          tab.eq(tabName).children('.elementor-tab-title').addClass('elementor-active');
          tab.eq(tabName).children('.elementor-tab-content').addClass('elementor-active');
          tab.eq(tabName).children('.elementor-tab-content').css('display', 'block');
        }); //queue
      } //if hash
    } //hash.length
  });
< /script>

Aページのリンク先の#ハッシュタグを変更した際は、上記の8行目の箇所を変更してください。

検索
Elementorカテゴリ
Sponsored Links

Announce

New
arrival

2019 collection

Let’s face it, no look is really complete without the right finishes. Not to the best of standards, anyway (just tellin’ it like it is, babe). Upgrading your shoe game. Platforms, stilettos, wedges, mules, boots—stretch those legs next time you head out, then rock sliders, sneakers, and flats when it’s time to chill.

Announce

New
arrival

2019 collection

Let’s face it, no look is really complete without the right finishes. Not to the best of standards, anyway (just tellin’ it like it is, babe). Upgrading your shoe game. Platforms, stilettos, wedges, mules, boots—stretch those legs next time you head out, then rock sliders, sneakers, and flats when it’s time to chill.