DynamicTabs_gz

一个简易tabs标签页,只需创建该类的实例,按需传入配置即可在页面上创建

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greatest.deepsurf.us/scripts/517538/1485921/DynamicTabs_gz.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Autor
hgztask
Wersja
0.2
Utworzono
15-11-2024
Zaktualizowano
17-11-2024
Rozmiar
11,4 KB
Licencja
Apache-2.0

DynamicTabs_gz

说明

  1. 一个简易Tabs标签页,只需创建该类的实例,按需传入选项卡配置即可在页面上创建, 支持设置自定义样式。
  2. 支持手动切换激活的选项卡。
  3. 支持动态修改选项卡位置。

实例

 // 示例选项卡配置
const tabsConfig = [
    //id不要重复,title也不可重复
    {id: 'tab1', title: '选项卡1', content: '<p>这是选项卡1的内容。</p>'},
    {id: 'tab2', title: '选项卡2', content: '<p>这是选项卡2的内容。</p>'},
    {id: 'tab3', title: '选项卡3', content: '<p>这是选项卡3的内容。</p>'},
];

// 自定义样式和事件处理类名
const options = {
    // 设置标签页位置,默认为 top,可选值有 top、bottom、left、right
    tabPosition: "left",
    /**
     *  追加自定义样式
     */
    styles: `
                /* 自定义样式 */
                .my-custom-tab-button {
                    font-size: 16px;
                }
                .my-custom-tab-content {
                    background-color: #f9f9f9;
                }
            `,
    // 自定义类名
    classes: {
        // 选项卡按钮样式
        tabButton: 'my-custom-tab-button',
        tabButtonActive: 'my-custom-tab-button-active',
        tabContent: 'my-custom-tab-content',
        tabContentActive: 'my-custom-tab-content-active'
    },
    backgroundColor: '#eee',
    borderColor: '#ddd',
    textColor: '#333',
    fontWeight: 'bold',
    activeBackgroundColor: '#0056b3',
    activeTextColor: '#fff',
    contentBorderColor: '#bbb',
    contentBackgroundColor: '#ffffff',
    onTabClick: (id, title, content) => {
        console.log(id, title, content)
    },
};

// 创建动态选项卡实例
try {
    const dynamicTabsGz = new DynamicTabs_gz('#tabs-container', tabsConfig, options);
    //手动切换激活的选项卡
    //通过标题激活选项卡
    dynamicTabsGz.activateTabTitle("选项卡2");
    //通过id激活选项卡
    dynamicTabsGz.activateTabId("tab1");
    //动态修改选项卡位置
    dynamicTabsGz.setTabPosition("right");
} catch (error) {
    console.error(error.message);
}