使用cbpFWTabs打开特定的选项卡 [英] Open a specific tab with cbpFWTabs

查看:127
本文介绍了使用cbpFWTabs打开特定的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 the page but it doesn't recognize the tabs or items arrays:

    <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

The tab source code is here: https://github.com/codrops/FullWidthTabs/blob/master/js/cbpFWTabs.js

我确定必须有一种更简单的方法吗?

I am sure there must be an easier way?

推荐答案

事实证明,它比我想象的要简单-只需在锚点上调用click事件即可.

It turned out to be easier than I thought -- simply invoke the click event on the anchor:

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

并向锚添加ID:

 <li><a id="settings-section" href="#section-bar-2" class="icon icon-box"><span>Settings</span></a></li>

这篇关于使用cbpFWTabs打开特定的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆