Open a specific tab with cbpFWTabs

前端 未结 4 876
忘掉有多难
忘掉有多难 2021-01-27 04:34

I am using cbpFWTabs (http://tympanus.net/Development/TabStylesInspiration/) but want to open a specific tab upon page load. I have tried to emulate the show method like this in

4条回答
  •  失恋的感觉
    2021-01-27 05:25

    OPs solution did not work for me, I had to do this:

    var triggers = [].slice.call( tabs.querySelectorAll( 'nav > ul > li' ) );
        document.getElementById('first-tab').addEventListener('click', function() {
    });
    
    if ( location.hash != 0 && location.hash == '#content' ){
         triggers[1].click();
      }
    

    Where 'first-tab' is the ID of your first tab's anchor:

    contact
    

    'content' is the reference in your URL: page.html#content

    Changing 'x' in triggers[x] will open the tabbed content corresponding to the hash on page load starting at 0 (so '1' in the example above will open the second tab on the page.)

    A downside is that upon changing tabbed item the hash remains the same; maybe someone can improve upon this.

提交回复
热议问题