灵活 jQuery选项卡接口插件 SmartTab

  • 源码大小:285.17KB
  • 所需积分:1积分
  • 源码编号:19JP-3450
  • 浏览次数:703次
  • 最后更新:2023年06月14日
  • 所属栏目:滑块
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

SmartTab是一个强大且高度可定制的jQuery插件,用于创建具有酷炫动画效果的选项卡式界面。

它支持ajax内容、键盘导航、Bootstrap 5、第三方CSS动画库,并与所有主要浏览器兼容。

如何使用它:

1.在网页上包含jQuery库和SmartTab.js脚本。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/dist/js/jquery.smartTab.js"></script>

2.在网页上包含所需的样式表。所有可能的主题:

  • 违约
  • 阻碍
  • 精英
  • 锻造
  • 药丸
  1. <!-- All in one -->
  2. <link href="/path/to/dist/css/smart_tab_all.min.css" rel="stylesheet" />
  3.  
  4. <!-- Default Theme -->
  5. <link href="/path/to/dist/css/smart_tab.min.css" rel="stylesheet" />
  6.  
  7. <!-- Blocks Theme -->
  8. <link href="/path/to/dist/css/smart_tab_blocks.min.css" rel="stylesheet" />
  9.  
  10. <!-- Brick Theme -->
  11. <link href="/path/to/dist/css/smart_tab_brick.min.css" rel="stylesheet" />
  12.  
  13. <!-- Elite Theme -->
  14. <link href="/path/to/dist/css/smart_tab_elite.min.css" rel="stylesheet" />
  15.  
  16. <!-- Forge Theme -->
  17. <link href="/path/to/dist/css/smart_tab_forge.min.css" rel="stylesheet" />
  18.  
  19. <!-- Bootstrap Pills Theme -->
  20. <link href="/path/to/dist/css/smart_tab_pills.min.css" rel="stylesheet" />

3.选项卡式界面所需的标记结构。

  1. <div id="smarttab">
  2.  
  3. <!-- Tabs -->
  4. <ul class="nav">
  5. <li>
  6. <a class="nav-link" href="#tab-1">
  7. Tab 1
  8. </a>
  9. </li>
  10. <li>
  11. <a class="nav-link" href="#tab-2">
  12. Tab 2
  13. </a>
  14. </li>
  15. <li>
  16. <a class="nav-link" href="#tab-3">
  17. Tab 3
  18. </a>
  19. </li>
  20. </ul>
  21.  
  22. <!-- Tabbed Content -->
  23. <div class="tab-content">
  24. <div id="tab-1" class="tab-pane" role="tabpanel">
  25. Tab content 1
  26. </div>
  27. <div id="tab-2" class="tab-pane" role="tabpanel">
  28. Tab content 2
  29. </div>
  30. <div id="tab-3" class="tab-pane" role="tabpanel">
  31. Tab content 3
  32. </div>
  33. </div>
  34. </div>

4.调用吨容器上的插件并完成。

  1. $('#smarttab').smartTab();

5.使用以下选项自定义插件。

  1. $('#smarttab').smartTab({
  2.  
  3. // Selected Tab, 0 = first tab
  4. selected: 0,
  5.  
  6. // theme name
  7. theme: 'default',
  8.  
  9. // Justified layout for tabs
  10. justified: true,
  11.  
  12. // Auto adjust content height
  13. autoAdjustHeight: true,
  14.  
  15. // Supports for Back button
  16. backButtonSupport: true,
  17. // Enables URL hash
  18. enableURLhash: true,
  19. // Configs animations here
  20. transition: {
  21.  
  22. // Animation effect on navigation
  23. // none|fade|slideHorizontal|slideVertical|slideSwing|css(Animation CSS class also need to specify)
  24. animation: 'none',
  25. // Animation speed.
  26. speed: '400',
  27. // Easing function.
  28. // Requires jQuery easing plugin
  29. easing: '',
  30. // Only used if animation is 'css'
  31. prefixCss: '',
  32. fwdShowCss: '',
  33. fwdHideCss: '',
  34. bckShowCss: '',
  35. bckHideCss: '',
  36.  
  37. },
  38.  
  39. // Auto switches between tabs
  40. autoProgress: {
  41. // enable
  42. enabled: false,
  43. // interval in ms
  44. interval: 3500,
  45.  
  46. // stop on focus
  47. stopOnFocus: true
  48.  
  49. },
  50.  
  51. // Keyboard navigation
  52. keyboardSettings: {
  53.  
  54. // enable
  55. keyNavigation: true,
  56.  
  57. // keycodes
  58. keyLeft: [37, 38],
  59. keyRight: [39, 40],
  60. keyHome: [36],
  61. keyEnd: [35],
  62.  
  63. },
  64.  
  65. // CSS Class settings
  66. style: {
  67. mainCss: 'st',
  68. navCss: 'nav',
  69. navLinkCss: 'nav-link',
  70. contentCss: 'tab-content',
  71. contentPanelCss: 'tab-pane',
  72. themePrefixCss: 'st-theme-',
  73. justifiedCss: 'st-justified',
  74. anchorDefaultCss: 'default',
  75. anchorActiveCss: 'active',
  76. loaderCss: 'st-loading'
  77. },
  78.  
  79. // Callback function for content loading
  80. getContent: null,
  81.  
  82. });

6.覆盖默认的CSS变量来创建自己的样式。

  1. :root {
  2. --st-background: unset,
  3. --st-border: 1px solid #eeeeee,
  4. --st-anchor-default-primary-color: #f8f9fa;
  5. --st-anchor-default-secondary-color: #b0b0b1;
  6. --st-anchor-active-primary-color: #009EF7;
  7. --st-anchor-active-secondary-color: #ffffff;
  8. --st-anchor-disabled-primary-color: #f8f9fa;
  9. --st-anchor-disabled-secondary-color: #dbe0e5;
  10. --st-loader-color: #009EF7;
  11. --st-loader-background-color: #f8f9fa;
  12. --st-loader-background-wrapper-color: rgba(255, 255, 255, 0.7);
  13. }

7.API方法。

  1. // goto the next tab
  2. $('#smarttab').smartTab("next");
  3.  
  4. // back to the previous tab
  5. $('#smarttab').smartTab("prev");
  6.  
  7. // goto the first tab
  8. $('#smarttab').smartTab("first");
  9.  
  10. // goto the last tab
  11. $('#smarttab').smartTab("last");
  12.  
  13. // reset tabs
  14. $('#smarttab').smartTab("reset");
  15.  
  16. // goto a specific tab
  17. $('#smarttab').smartTab("goToTab", 3);
  18.  
  19. // update options
  20. $('#smarttab').smartTab("setOptions", options);
  21.  
  22. // get options
  23. $('#smarttab').smartTab("getOptions");
  24.  
  25. // get the tab info
  26. $('#smarttab').smartTab("getInfo");
  27.  
  28. // show/hide the loading animation
  29. $('#smarttab').smartTab("loader", "show");
  30. $('#smarttab').smartTab("loader", "hide");
  31.  
  32. // adjust the content height of the current step
  33. $('#smarttab').smartTab("fixHeight");

更多示例:

  • 典型的
  • 底部
  • 倍数
  • 竖的

更新日志:

版本4.0.2(2022-07-31)

  • 已修复:快速导航导致页面选择不当
  • 更改:代码改进

版本4.0.1(2022-07-11)

  • 添加:支持jQuery Slim版本
  • 添加:公共函数fixHeight
  • 添加:公共函数getInfo以获取选项卡索引和tota选项卡
  • 添加了:带有force参数的goToTab函数
  • 添加:新主题
  • 添加:颜色可以使用CSS变量动态更改。
  • 添加:Bootstrap 5支持
  • 添加:初始化事件
  • 添加:将CSS类名移动到选项
  • 添加:可以扩展过渡动画
  • 添加:CSS动画支持过渡动画。支持Animate.css
  • 更改:JavaScript和CSS代码被重写
  • 更改:强制所有CSS主题
  • 更改:使大多数选项可以通过setOptions功能更改
  • 更改:用最少且有意义的名称重写选项名称和属性
  • 更改:改进了过渡动画
  • 已移除:黑暗模式已移除。添加了CSS变量支持来更改任何颜色。
  • 删除:删除了方向选项,而是将st垂直CSS类添加到主元素中

2020-06-15

  • v3.1.1:一些优化

2020-05-09

  • v3.0.1:优化了init方法

2020-05-04

  • v3.0全新选项卡。
  • 更新的文档。

2015-02-02

  • 使现代化

预览截图