carousel.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>镜像站@通用轮播 - 在线演示 - Layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="format-detection" content="telephone=no">
  12. <script>
  13. ;!function(){self!==parent&&(location.href="http://www.baidu.com/")}();
  14. </script>
  15. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css?t=1632428048355" media="all">
  16. <link rel="stylesheet" href="/public/static/css/global.css" tppabs="http://res.layui.com/static/css/global.css?t=1632428048355-19" media="all">
  17. <style>
  18. /* 为了区分效果 */
  19. div[carousel-item]>*{text-align: center; line-height: 280px; color: #fff;}
  20. div[carousel-item]>*:nth-child(2n){background-color: #009688;}
  21. div[carousel-item]>*:nth-child(2n+1){background-color: #5FB878;}
  22. #test2 div[carousel-item]>*{line-height: 120px;}
  23. </style>
  24. </head>
  25. <body>
  26. <div class="layui-layout layui-layout-admin">
  27. <div class="layui-header header header-demo" autumn>
  28. <div class="layui-fluid">
  29. <a class="logo" href="../index.html" tppabs="http://www.layui.com/">
  30. <img src="/public/static/images/layui/logo.png" tppabs="http://res.layui.com/static/images/layui/logo.png" alt="layui">
  31. </a>
  32. <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
  33. <div class="layui-hide-xs site-notice"></div>
  34. <ul class="layui-nav" id="LAY_NAV_TOP">
  35. <li class="layui-nav-item ">
  36. <a href="../doc/index.html" tppabs="http://www.layui.com/doc/">文档</a>
  37. </li>
  38. <li class="layui-nav-item layui-this">
  39. <a href="index.html" tppabs="http://www.layui.com/demo/">示例</a>
  40. </li>
  41. <li class="layui-nav-item">
  42. <a href="javascript:;">
  43. <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>-->
  44. 周边
  45. </a>
  46. <dl class="layui-nav-child layui-nav-child-c">
  47. <dd class="layui-hide-sm layui-show-xs" lay-unselect>
  48. <a href="https://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">问题反馈</a>
  49. <hr>
  50. </dd>
  51. <dd lay-unselect><a href="../alone.html" tppabs="http://www.layui.com/alone.html" target="_blank" lay-unselect>独立组件</a></dd>
  52. <dd lay-unselect><a href="../../fly.layui.com/extend/index.html" target="_blank">扩展组件</a></dd>
  53. </dl>
  54. </li>
  55. <li class="layui-nav-item layui-hide-xs">
  56. <a href="http://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">反馈</a>
  57. </li>
  58. </ul>
  59. </div>
  60. </div>
  61. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  62. <!--[if lt IE 9]>
  63. <script src="../../other/html5shiv/r29/html5.min.js" tppabs="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  64. <script src="../../other/respond.js/1.4.2/respond.min.js" tppabs="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  65. <![endif]-->
  66. <div class="layui-side layui-bg-black">
  67. <div class="layui-side-scroll">
  68. <ul class="layui-nav layui-nav-tree site-demo-nav">
  69. <li class="layui-nav-item layui-nav-itemed">
  70. <a class="javascript:;" href="javascript:;">演示</a>
  71. <dl class="layui-nav-child">
  72. <dd>
  73. <a href="index.html" tppabs="http://www.layui.com/demo/">调试预览</a>
  74. </dd>
  75. </dl>
  76. </li>
  77. <li class="layui-nav-item layui-nav-itemed">
  78. <a class="javascript:;" href="javascript:;">布局</a>
  79. <dl class="layui-nav-child">
  80. <dd class="">
  81. <a href="grid.html" tppabs="http://www.layui.com/demo/grid.html">栅格</a>
  82. </dd>
  83. <dd class="">
  84. <a href="admin.html" tppabs="http://www.layui.com/demo/admin.html">框架</a>
  85. </dd>
  86. </dl>
  87. </li>
  88. <li class="layui-nav-item layui-nav-itemed">
  89. <a class="javascript:;" href="javascript:;">基本元素</a>
  90. <dl class="layui-nav-child">
  91. <dd class="">
  92. <a href="button.html" tppabs="http://www.layui.com/demo/button.html">按钮</a>
  93. </dd>
  94. <dd class="">
  95. <a href="form.html" tppabs="http://www.layui.com/demo/form.html">表单</a>
  96. </dd>
  97. <dd class="">
  98. <a href="nav.html" tppabs="http://www.layui.com/demo/nav.html">导航 / 面包屑</a>
  99. </dd>
  100. <dd class="">
  101. <a href="menu.html" tppabs="http://www.layui.com/demo/menu.html">基础菜单</a>
  102. </dd>
  103. <dd class="">
  104. <a href="tab.html" tppabs="http://www.layui.com/demo/tab.html">选项卡</a>
  105. </dd>
  106. <dd class="">
  107. <a href="progress.html" tppabs="http://www.layui.com/demo/progress.html">进度条</a>
  108. </dd>
  109. <dd class="">
  110. <a href="panel.html" tppabs="http://www.layui.com/demo/panel.html">面板</a>
  111. </dd>
  112. <dd class="">
  113. <a href="badge.html" tppabs="http://www.layui.com/demo/badge.html">徽章</a>
  114. </dd>
  115. <dd class="">
  116. <a href="timeline.html" tppabs="http://www.layui.com/demo/timeline.html">时间线</a>
  117. </dd>
  118. <dd class="">
  119. <a href="table-element.html" tppabs="http://www.layui.com/demo/table-element.html">静态表格</a>
  120. </dd>
  121. <dd class="">
  122. <a href="anim.html" tppabs="http://www.layui.com/demo/anim.html">动画</a>
  123. </dd>
  124. <dd class="">
  125. <a href="auxiliar.html" tppabs="http://www.layui.com/demo/auxiliar.html">辅助元素</a>
  126. </dd>
  127. </dl>
  128. </li>
  129. <li class="layui-nav-item layui-nav-itemed">
  130. <a class="javascript:;" href="javascript:;">组件示例</a>
  131. <dl class="layui-nav-child">
  132. <dd class="">
  133. <a href="layer.html" tppabs="http://www.layui.com/demo/layer.html">
  134. 弹出层
  135. </a>
  136. </dd>
  137. <dd class="">
  138. <a href="laydate.html" tppabs="http://www.layui.com/demo/laydate.html">
  139. 日期与时间选择
  140. </a>
  141. </dd>
  142. <dd class="">
  143. <a href="table.html" tppabs="http://www.layui.com/demo/table.html">
  144. 数据表格
  145. </a>
  146. </dd>
  147. <dd class="">
  148. <a href="laypage.html" tppabs="http://www.layui.com/demo/laypage.html">
  149. 分页
  150. </a>
  151. </dd>
  152. <dd class="">
  153. <a href="dropdown.html" tppabs="http://www.layui.com/demo/dropdown.html">
  154. 下拉菜单
  155. </a>
  156. </dd>
  157. <dd class="">
  158. <a href="upload.html" tppabs="http://www.layui.com/demo/upload.html">
  159. 文件上传
  160. </a>
  161. </dd>
  162. <dd class="">
  163. <a href="transfer.html" tppabs="http://www.layui.com/demo/transfer.html">
  164. 穿梭框
  165. </a>
  166. </dd>
  167. <dd class="">
  168. <a href="tree.html" tppabs="http://www.layui.com/demo/tree.html">
  169. 树形组件
  170. </a>
  171. </dd>
  172. <dd class="">
  173. <a href="colorpicker.html" tppabs="http://www.layui.com/demo/colorpicker.html">
  174. 颜色选择器
  175. </a>
  176. </dd>
  177. <dd class="">
  178. <a href="slider.html" tppabs="http://www.layui.com/demo/slider.html">
  179. 滑块
  180. </a>
  181. </dd>
  182. <dd class="">
  183. <a href="rate.html" tppabs="http://www.layui.com/demo/rate.html">
  184. 评分
  185. </a>
  186. </dd>
  187. <dd class="layui-this">
  188. <a href="carousel.html" tppabs="http://www.layui.com/demo/carousel.html">
  189. 轮播
  190. </a>
  191. </dd>
  192. <dd class="">
  193. <a href="laytpl.html" tppabs="http://www.layui.com/demo/laytpl.html">
  194. 模板引擎
  195. </a>
  196. </dd>
  197. <dd class="">
  198. <a href="layedit.html" tppabs="http://www.layui.com/demo/layedit.html">
  199. 富文本编辑器
  200. </a>
  201. </dd>
  202. <dd class="">
  203. <a href="flow.html" tppabs="http://www.layui.com/demo/flow.html">
  204. 流加载
  205. </a>
  206. </dd>
  207. <dd class="">
  208. <a href="util.html" tppabs="http://www.layui.com/demo/util.html">
  209. 工具模块
  210. </a>
  211. </dd>
  212. <dd class="">
  213. <a href="code.html" tppabs="http://www.layui.com/demo/code.html">
  214. 文本行修饰
  215. </a>
  216. </dd>
  217. </dl>
  218. </li>
  219. <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
  220. </ul>
  221. </div>
  222. </div>
  223. <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
  224. <ul class="layui-tab-title site-demo-title">
  225. <li class="layui-this">预览</li>
  226. <li>查看代码</li>
  227. <li>帮助</li>
  228. </ul>
  229. <div class="layui-body layui-tab-content site-demo site-demo-body">
  230. <div class="layui-tab-item layui-show">
  231. <div class="layui-main">
  232. <div id="LAY_preview">
  233. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  234. <legend>常规轮播</legend>
  235. </fieldset>
  236. <div class="layui-carousel" id="test1" lay-filter="test1">
  237. <div carousel-item>
  238. <div>条目1</div>
  239. <div>条目2</div>
  240. <div>条目3</div>
  241. <div>条目4</div>
  242. <div>条目5</div>
  243. </div>
  244. </div>
  245. <div class="layui-carousel" id="test2" style="margin-top: 15px;">
  246. <div carousel-item>
  247. <div>条目1</div>
  248. <div>条目2</div>
  249. </div>
  250. </div>
  251. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  252. <legend>设定各种参数</legend>
  253. </fieldset>
  254. <div class="layui-form">
  255. <div class="layui-form-item">
  256. <div class="layui-inline">
  257. <label class="layui-form-label">宽高</label>
  258. <div class="layui-input-inline" style="width: 98px;">
  259. <input type="tel" name="width" value="600" autocomplete="off" placeholder="width" class="layui-input demoSet">
  260. </div>
  261. <div class="layui-input-inline" style="width: 98px;">
  262. <input type="tel" name="height" value="280" autocomplete="off" placeholder="height" class="layui-input demoSet">
  263. </div>
  264. </div>
  265. </div>
  266. <div class="layui-form-item">
  267. <label class="layui-form-label">动画类型</label>
  268. <div class="layui-input-block">
  269. <div class="layui-btn-group demoTest" style="margin-top: 5px;">
  270. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-type="set" data-key="anim" data-value="default">左右切换</button>
  271. <button class="layui-btn layui-btn-sm" data-type="set" data-key="anim" data-value="updown">上下切换</button>
  272. <button class="layui-btn layui-btn-sm" data-type="set" data-key="anim" data-value="fade">渐隐渐显</button>
  273. </div>
  274. </div>
  275. </div>
  276. <div class="layui-form-item">
  277. <label class="layui-form-label">箭头状态</label>
  278. <div class="layui-input-block">
  279. <div class="layui-btn-group demoTest" style="margin-top: 5px;">
  280. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-type="set" data-key="arrow" data-value="hover">悬停显示</button>
  281. <button class="layui-btn layui-btn-sm" data-type="set" data-key="arrow" data-value="always">始终显示</button>
  282. <button class="layui-btn layui-btn-sm" data-type="set" data-key="arrow" data-value="none">不显示</button>
  283. </div>
  284. </div>
  285. </div>
  286. <div class="layui-form-item">
  287. <label class="layui-form-label">指示器位置</label>
  288. <div class="layui-input-block">
  289. <div class="layui-btn-group demoTest" style="margin-top: 5px;">
  290. <button class="layui-btn layui-btn-sm" style="background-color: #5FB878;" data-key="indicator" data-type="set" data-value="inside">容器内部</button>
  291. <button class="layui-btn layui-btn-sm" data-type="set" data-key="indicator" data-value="outside">容器外部</button>
  292. <button class="layui-btn layui-btn-sm" data-type="set" data-key="indicator" data-value="none">不显示</button>
  293. </div>
  294. </div>
  295. </div>
  296. <div class="layui-form-item">
  297. <div class="layui-inline">
  298. <label class="layui-form-label">自动切换</label>
  299. <div class="layui-input-block">
  300. <input type="checkbox" name="switch" lay-skin="switch" checked lay-text="ON|OFF" lay-filter="autoplay">
  301. </div>
  302. </div>
  303. <div class="layui-inline">
  304. <label class="layui-form-label" style="width: auto;">时间间隔</label>
  305. <div class="layui-input-inline" style="width: 120px;">
  306. <input type="tel" name="interval" value="3000" autocomplete="off" placeholder="毫秒" class="layui-input demoSet">
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. <div class="layui-carousel" id="test3" lay-filter="test4">
  312. <div carousel-item>
  313. <div>条目1</div>
  314. <div>条目2</div>
  315. <div>条目3</div>
  316. <div>条目4</div>
  317. <div>条目5</div>
  318. </div>
  319. </div>
  320. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  321. <legend>填充轮播元素 - 以图片为例</legend>
  322. </fieldset>
  323. <div class="layui-carousel" id="test10">
  324. <div carousel-item>
  325. <div><img src="/public/static/images/layui/demo/1.png" tppabs="http://res.layui.com/static/images/layui/demo/1.png"></div>
  326. <div><img src="/public/static/images/layui/demo/2.png" tppabs="http://res.layui.com/static/images/layui/demo/2.png"></div>
  327. <div><img src="/public/static/images/layui/demo/3.png" tppabs="http://res.layui.com/static/images/layui/demo/3.png"></div>
  328. <div><img src="/public/static/images/layui/demo/4.png" tppabs="http://res.layui.com/static/images/layui/demo/4.png"></div>
  329. <div><img src="/public/static/images/layui/demo/5.png" tppabs="http://res.layui.com/static/images/layui/demo/5.png"></div>
  330. <div><img src="/public/static/images/layui/demo/6.png" tppabs="http://res.layui.com/static/images/layui/demo/6.png"></div>
  331. <div><img src="/public/static/images/layui/demo/7.png" tppabs="http://res.layui.com/static/images/layui/demo/7.png"></div>
  332. </div>
  333. </div>
  334. </div>
  335. <blockquote class="layui-elem-quote" style="margin-top: 30px;">
  336. 更多我们未能呈现的示例,还有待您在阅读文档、以及不断使用的过程,去深入挖掘。
  337. </blockquote>
  338. <div style="margin: 15px 0 100px; padding-bottom: 100px;">
  339. </div>
  340. </div>
  341. </div>
  342. <div class="layui-tab-item">
  343. <textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly>
  344. <!DOCTYPE html>
  345. <html>
  346. <head>
  347. <meta charset="utf-8">
  348. <title>镜像站@Layui</title>
  349. <meta name="renderer" content="webkit">
  350. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  351. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  352. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
  353. <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
  354. </head>
  355. </textarea>
  356. </div>
  357. <div class="layui-tab-item">
  358. <div class="layui-main">
  359. <p></p>
  360. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  361. <legend>相关</legend>
  362. </fieldset>
  363. <a class="layui-btn layui-btn-normal" href="../doc/modules/carousel.html" tppabs="http://www.layui.com/doc/modules/carousel.html" target="_blank">表单元素文档</a>
  364. </div>
  365. </div>
  366. </div>
  367. </div>
  368. <div class="layui-footer footer footer-demo">
  369. <p>
  370. Copyright &copy; 2021 <a href="../index.html" tppabs="http://www.layui.com/">「本站仅为 layui 文档保留的镜像站点,与官方无关」</a> MIT Licensed</p>
  371. <p>
  372. <a href="../about/disclaimer.html" tppabs="http://www.layui.com/about/disclaimer.html" target="_blank">免责声明</a>
  373. <a href="../about/relatedlinks.html" tppabs="http://www.layui.com/about/relatedlinks.html" target="_blank">友链</a>
  374. <a href="javascript:;" site-event="weixinmp">公众号</a>
  375. </p>
  376. <div class="site-union">
  377. <p class="site-union-desc">
  378. <span>
  379. </span>
  380. </p>
  381. </div>
  382. </div>
  383. <script>
  384. window.global = {
  385. pageType: 'demo'
  386. ,preview: function(){
  387. var preview = document.getElementById('LAY_preview');
  388. return preview ? preview.innerHTML : '';
  389. }()
  390. };
  391. </script>
  392. <div class="site-tree-mobile layui-hide">
  393. <i class="layui-icon layui-icon-spread-left"></i>
  394. </div>
  395. <div class="site-mobile-shade"></div>
  396. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048355" charset="utf-8"></script>
  397. <script>
  398. layui.config({
  399. base: '/public/static/lay/modules/layui/'
  400. ,version: '1632428048355'
  401. }).use('global');
  402. </script>
  403. </div>
  404. <div id="LAY_democodejs">
  405. <script>
  406. layui.use(['carousel', 'form'], function(){
  407. var carousel = layui.carousel
  408. ,form = layui.form;
  409. //常规轮播
  410. carousel.render({
  411. elem: '#test1'
  412. ,arrow: 'always'
  413. });
  414. //改变下时间间隔、动画类型、高度
  415. carousel.render({
  416. elem: '#test2'
  417. ,interval: 1800
  418. ,anim: 'fade'
  419. ,height: '120px'
  420. });
  421. //设定各种参数
  422. var ins3 = carousel.render({
  423. elem: '#test3'
  424. });
  425. //图片轮播
  426. carousel.render({
  427. elem: '#test10'
  428. ,width: '778px'
  429. ,height: '440px'
  430. ,interval: 5000
  431. });
  432. //事件
  433. carousel.on('change(test4)', function(res){
  434. console.log(res)
  435. });
  436. var $ = layui.$, active = {
  437. set: function(othis){
  438. var THIS = 'layui-bg-normal'
  439. ,key = othis.data('key')
  440. ,options = {};
  441. othis.css('background-color', '#5FB878').siblings().removeAttr('style');
  442. options[key] = othis.data('value');
  443. ins3.reload(options);
  444. }
  445. };
  446. //监听开关
  447. form.on('switch(autoplay)', function(){
  448. ins3.reload({
  449. autoplay: this.checked
  450. });
  451. });
  452. $('.demoSet').on('keyup', function(){
  453. var value = this.value
  454. ,options = {};
  455. if(!/^\d+$/.test(value)) return;
  456. options[this.name] = value;
  457. ins3.reload(options);
  458. });
  459. //其它示例
  460. $('.demoTest .layui-btn').on('click', function(){
  461. var othis = $(this), type = othis.data('type');
  462. active[type] ? active[type].call(this, othis) : '';
  463. });
  464. });
  465. </script>
  466. </div>
  467. </body>
  468. </html>