index.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <title>选项卡组件</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>选项卡</cite></a>
  7. </div>
  8. </div>
  9. <style>
  10. /* 这段样式只是用于演示 */
  11. </style>
  12. <div class="layui-fluid" id="component-tabs">
  13. <div class="layui-row">
  14. <div class="layui-col-md12">
  15. <div class="layui-card">
  16. <div class="layui-card-header">默认风格</div>
  17. <div class="layui-card-body">
  18. <div class="layui-tab">
  19. <ul class="layui-tab-title">
  20. <li class="layui-this">网站设置</li>
  21. <li>用户管理</li>
  22. <li>权限分配</li>
  23. <li>商品管理</li>
  24. <li>订单管理</li>
  25. </ul>
  26. <div class="layui-tab-content">
  27. <div class="layui-tab-item layui-show">
  28. 1. 高度默认自适应,也可以随意固宽。
  29. <br>2. Tab进行了响应式处理,所以无需担心数量多少。
  30. </div>
  31. <div class="layui-tab-item">内容2</div>
  32. <div class="layui-tab-item">内容3</div>
  33. <div class="layui-tab-item">内容4</div>
  34. <div class="layui-tab-item">内容5</div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="layui-card">
  40. <div class="layui-card-header">简洁风格</div>
  41. <div class="layui-card-body">
  42. <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
  43. <ul class="layui-tab-title">
  44. <li class="layui-this">网站设置</li>
  45. <li>用户管理</li>
  46. <li>权限分配</li>
  47. <li>商品管理</li>
  48. <li>订单管理</li>
  49. </ul>
  50. <div class="layui-tab-content">
  51. <div class="layui-tab-item layui-show">
  52. 你也可以监听 tab 事件
  53. </div>
  54. <div class="layui-tab-item">内容2</div>
  55. <div class="layui-tab-item">内容3</div>
  56. <div class="layui-tab-item">内容4</div>
  57. <div class="layui-tab-item">内容5</div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="layui-card">
  63. <div class="layui-card-header">卡片风格</div>
  64. <div class="layui-card-body">
  65. <div class="layui-tab layui-tab-card">
  66. <ul class="layui-tab-title">
  67. <li class="layui-this">网站设置</li>
  68. <li>用户管理</li>
  69. <li>权限分配</li>
  70. <li>商品管理</li>
  71. <li>订单管理</li>
  72. </ul>
  73. <div class="layui-tab-content">
  74. <div class="layui-tab-item layui-show">默认宽度是相对于父元素100%适应的,你也可以固定宽度。</div>
  75. <div class="layui-tab-item">2</div>
  76. <div class="layui-tab-item">3</div>
  77. <div class="layui-tab-item">44444</div>
  78. <div class="layui-tab-item">5</div>
  79. <div class="layui-tab-item">6</div>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="layui-col-md12">
  86. <div class="layui-card">
  87. <div class="layui-card-header">动态操作</div>
  88. <div class="layui-card-body">
  89. <div class="layui-tab" lay-filter="demo" lay-allowclose="true">
  90. <ul class="layui-tab-title">
  91. <li class="layui-this" lay-id="11">网站设置</li>
  92. <li lay-id="22">用户管理</li>
  93. <li lay-id="33">权限分配</li>
  94. <li lay-id="44">商品管理</li>
  95. <li lay-id="55">订单管理</li>
  96. </ul>
  97. <div class="layui-tab-content">
  98. <div class="layui-tab-item layui-show">内容1</div>
  99. <div class="layui-tab-item">内容2</div>
  100. <div class="layui-tab-item">内容3</div>
  101. </div>
  102. </div>
  103. <div class="layui-btn-container">
  104. <button class="layui-btn site-demo-active" data-type="tabAdd">新增一个项</button>
  105. <button class="layui-btn site-demo-active" data-type="tabDelete">删除:用户管理</button>
  106. <button class="layui-btn site-demo-active" data-type="tabChange">切换到:权限分配</button>
  107. </div>
  108. </div>
  109. </div>
  110. <div class="layui-card">
  111. <div class="layui-card-header">记录状态</div>
  112. <div class="layui-card-body">
  113. <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-hash">
  114. <ul class="layui-tab-title">
  115. <li class="layui-this" lay-id="11">网站设置</li>
  116. <li lay-id="22">用户管理</li>
  117. <li lay-id="33">权限分配</li>
  118. <li lay-id="44">商品管理</li>
  119. <li lay-id="55">订单管理</li>
  120. </ul>
  121. <div class="layui-tab-content" style="height: 165px;">
  122. <div class="layui-tab-item layui-show">
  123. 点击该Tab的任一标题,观察地址栏变化,再刷新页面。选项卡将会自动定位到上一次切换的项
  124. </div>
  125. <div class="layui-tab-item">内容2</div>
  126. <div class="layui-tab-item">内容3</div>
  127. <div class="layui-tab-item">内容4</div>
  128. <div class="layui-tab-item">内容5</div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <script>
  136. layui.use(['admin'], function(){
  137. var $ = layui.$
  138. ,admin = layui.admin
  139. ,element = layui.element
  140. ,router = layui.router();
  141. element.render();
  142. element.on('tab(component-tabs-brief)', function(obj){
  143. layer.msg(obj.index + ':' + this.innerHTML);
  144. });
  145. /* 触发事件 */
  146. var active = {
  147. tabAdd: function(){
  148. /* 新增一个Tab项 */
  149. element.tabAdd('demo', {
  150. title: '新选项'+ (Math.random()*1000|0) /* 用于演示 */
  151. ,content: '内容'+ (Math.random()*1000|0)
  152. ,id: new Date().getTime() /* 实际使用一般是规定好的id,这里以时间戳模拟下 */
  153. })
  154. }
  155. ,tabDelete: function(othis){
  156. /* 删除指定Tab项 */
  157. element.tabDelete('demo', '22');
  158. othis.addClass('layui-btn-disabled');
  159. }
  160. ,tabChange: function(){
  161. /* 切换到指定Tab项 */
  162. element.tabChange('demo', '33');
  163. }
  164. };
  165. $('#component-tabs .site-demo-active').on('click', function(){
  166. var othis = $(this), type = othis.data('type');
  167. active[type] ? active[type].call(this, othis) : '';
  168. });
  169. /* Hash地址的定位 */
  170. var layid = router.hash.replace(/^#layid=/, '');
  171. layid && element.tabChange('component-tabs-hash', layid);
  172. element.on('tab(component-tabs-hash)', function(elem){
  173. location.hash = '/'+ layui.router().path.join('/') + '#layid=' + $(this).attr('lay-id');
  174. });
  175. });
  176. </script>
  177. </div>