index.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <title>轮播</title>
  2. <style>
  3. /* 为了区分效果 */
  4. #LAY-demo-carousel div[carousel-item]>*{text-align: center; line-height: 280px; color: #666;}
  5. #LAY-demo-carousel div[carousel-item]>*:nth-child(2n){background-color: #E2E2E2;}
  6. #LAY-demo-carousel div[carousel-item]>*:nth-child(2n+1){background-color: #eee;}
  7. #test-carousel-normal-2 div[carousel-item]>*{line-height: 120px;}
  8. </style>
  9. <div class="layui-card layadmin-header">
  10. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  11. <a lay-href="">主页</a>
  12. <a><cite>组件</cite></a>
  13. <a><cite>轮播</cite></a>
  14. </div>
  15. </div>
  16. <div class="layui-fluid" id="LAY-demo-carousel">
  17. <div class="layui-row layui-col-space15">
  18. <div class="layui-col-md12">
  19. <div class="layui-card">
  20. <div class="layui-card-header">常规轮播</div>
  21. <div class="layui-card-body">
  22. <div class="layui-carousel" id="test-carousel-normal" lay-filter="test-carousel-normal">
  23. <div carousel-item="">
  24. <div>条目1</div>
  25. <div>条目2</div>
  26. <div>条目3</div>
  27. <div>条目4</div>
  28. <div>条目5</div>
  29. </div>
  30. </div>
  31. <div class="layui-carousel" id="test-carousel-normal-2" style="margin-top: 15px;">
  32. <div carousel-item="">
  33. <div>条目1</div>
  34. <div>条目2</div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="layui-col-md12">
  41. <div class="layui-card">
  42. <div class="layui-card-header">设定各种参数</div>
  43. <div class="layui-card-body">
  44. <div class="layui-form">
  45. <div class="layui-form-item">
  46. <div class="layui-inline">
  47. <label class="layui-form-label">宽高</label>
  48. <div class="layui-input-inline" style="width: 98px;">
  49. <input type="tel" name="width" value="600" autocomplete="off" placeholder="width" class="layui-input test-carousel-demoSet">
  50. </div>
  51. <div class="layui-input-inline" style="width: 98px;">
  52. <input type="tel" name="height" value="280" autocomplete="off" placeholder="height" class="layui-input test-carousel-demoSet">
  53. </div>
  54. </div>
  55. </div>
  56. <div class="layui-form-item">
  57. <label class="layui-form-label">动画类型</label>
  58. <div class="layui-input-block">
  59. <div class="layui-btn-group test-carousel-demoTest" style="margin-top: 5px;">
  60. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-type="set" data-key="anim" data-value="default">左右切换</button>
  61. <button class="layui-btn layui-btn-sm" data-type="set" data-key="anim" data-value="updown">上下切换</button>
  62. <button class="layui-btn layui-btn-sm" data-type="set" data-key="anim" data-value="fade">渐隐渐显</button>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="layui-form-item">
  67. <label class="layui-form-label">箭头状态</label>
  68. <div class="layui-input-block">
  69. <div class="layui-btn-group test-carousel-demoTest" style="margin-top: 5px;">
  70. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-type="set" data-key="arrow" data-value="hover">悬停显示</button>
  71. <button class="layui-btn layui-btn-sm" data-type="set" data-key="arrow" data-value="always">始终显示</button>
  72. <button class="layui-btn layui-btn-sm" data-type="set" data-key="arrow" data-value="none">不显示</button>
  73. </div>
  74. </div>
  75. </div>
  76. <div class="layui-form-item">
  77. <label class="layui-form-label">指示器位置</label>
  78. <div class="layui-input-block">
  79. <div class="layui-btn-group test-carousel-demoTest" style="margin-top: 5px;">
  80. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-key="indicator" data-type="set" data-value="inside">容器内部</button>
  81. <button class="layui-btn layui-btn-sm" data-type="set" data-key="indicator" data-value="outside">容器外部</button>
  82. <button class="layui-btn layui-btn-sm" data-type="set" data-key="indicator" data-value="none">不显示</button>
  83. </div>
  84. </div>
  85. </div>
  86. <div class="layui-form-item">
  87. <div class="layui-inline">
  88. <label class="layui-form-label">自动切换</label>
  89. <div class="layui-input-block">
  90. <input type="checkbox" name="switch" lay-skin="switch" checked="" lay-text="ON|OFF" lay-filter="test-carousel-autoplay">
  91. </div>
  92. </div>
  93. <div class="layui-inline">
  94. <label class="layui-form-label" style="width: auto;">时间间隔</label>
  95. <div class="layui-input-inline" style="width: 120px;">
  96. <input type="tel" name="interval" value="3000" autocomplete="off" placeholder="毫秒" class="layui-input test-carousel-demoSet">
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="layui-carousel" id="test-carousel-demo" lay-filter="test-carousel-demo">
  102. <div carousel-item="">
  103. <div>条目1</div>
  104. <div>条目2</div>
  105. <div>条目3</div>
  106. <div>条目4</div>
  107. <div>条目5</div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="layui-col-md12">
  114. <div class="layui-card">
  115. <div class="layui-card-header">填充轮播元素 - 以图片为例</div>
  116. <div class="layui-card-body">
  117. <div class="layui-carousel" id="test-carousel-img">
  118. <div carousel-item="">
  119. <div><img src="//res.layui.com/images/layui/demo/1.png"></div>
  120. <div><img src="//res.layui.com/images/layui/demo/2.png"></div>
  121. <div><img src="//res.layui.com/images/layui/demo/3.png"></div>
  122. <div><img src="//res.layui.com/images/layui/demo/4.png"></div>
  123. <div><img src="//res.layui.com/images/layui/demo/5.png"></div>
  124. <div><img src="//res.layui.com/images/layui/demo/6.png"></div>
  125. <div><img src="//res.layui.com/images/layui/demo/7.png"></div>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <script>
  134. layui.use(['admin', 'carousel', 'form'], function(){
  135. var carousel = layui.carousel
  136. ,form = layui.form;
  137. //常规轮播
  138. carousel.render({
  139. elem: '#test-carousel-normal'
  140. ,arrow: 'always'
  141. });
  142. //改变下时间间隔、动画类型、高度
  143. carousel.render({
  144. elem: '#test-carousel-normal-2'
  145. ,interval: 1800
  146. ,anim: 'fade'
  147. ,height: '120px'
  148. });
  149. //设定各种参数
  150. var ins3 = carousel.render({
  151. elem: '#test-carousel-demo'
  152. });
  153. //图片轮播
  154. carousel.render({
  155. elem: '#test-carousel-img'
  156. ,width: '778px'
  157. ,height: '440px'
  158. ,interval: 5000
  159. });
  160. //事件
  161. carousel.on('change(test-carousel-demo)', function(res){
  162. console.log(res)
  163. });
  164. var $ = layui.$, active = {
  165. set: function(othis){
  166. var THIS = 'layui-bg-normal'
  167. ,key = othis.data('key')
  168. ,options = {};
  169. othis.css('background-color', '#5FB878').siblings().removeAttr('style');
  170. options[key] = othis.data('value');
  171. ins3.reload(options);
  172. }
  173. };
  174. //监听开关
  175. form.on('switch(test-carousel-autoplay)', function(){
  176. ins3.reload({
  177. autoplay: this.checked
  178. });
  179. });
  180. $('.test-carousel-demoSet').on('keyup', function(){
  181. var value = this.value
  182. ,options = {};
  183. if(!/^\d+$/.test(value)) return;
  184. options[this.name] = value;
  185. ins3.reload(options);
  186. });
  187. //其它示例
  188. $('.test-carousel-demoTest .layui-btn').on('click', function(){
  189. var othis = $(this), type = othis.data('type');
  190. active[type] ? active[type].call(this, othis) : '';
  191. });
  192. });
  193. </script>