DynamicTabs_gz

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

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/517538/1485921/DynamicTabs_gz.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

ผู้เขียน
hgztask
เวอร์ชัน
0.2
สร้างเมื่อ
15-11-2024
อัปเดตเมื่อ
17-11-2024
Size
11.4 กิโลไบต์
สัญญาอนุญาต
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);
}