使用 cbpFWTabs 打开特定选项卡

2023-11-30

我正在使用 cbpFWTabs (http://tympanus.net/Development/TabStylesInspiration/)但想要在页面加载时打开特定选项卡。我尝试在页面中模拟这样的显示方法,但它无法识别选项卡或项目数组:

    <script type="text/javascript">

            // tabs elems
            this.tabs = [].slice.call( this.el.querySelectorAll( 'nav > ul > li' ) );
            // content items
            this.items = [].slice.call( this.el.querySelectorAll( '.content-wrap > section' ) );

            if( this.current >= 0 ) {
                    this.tabs[ this.current ].className = this.items[ this.current ].className = '';
            }
            // change current
            this.current = idx != undefined ? idx : this.options.start >= 0 && this.options.start < this.items.length ? this.options.start : 0;
            this.tabs[ this.current ].className = 'tab-current';
            this.items[ this.current ].className = 'content-current';
    };

    tabIndex = 1;
    showTab(tabIndex);

</script>

选项卡源代码在这里:https://github.com/codrops/FullWidthTabs/blob/master/js/cbpFWTabs.js

我确信一定有更简单的方法吗?


事实证明,这比我想象的要容易——只需调用锚点上的单击事件即可:

$('#settings-section')[0].click();

并向锚添加一个 id:

 <li><a id="settings-section" href="#section-bar-2" class="icon icon-box"><span>Settings</span></a></li>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 cbpFWTabs 打开特定选项卡 的相关文章

随机推荐