list.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <title>layer 组件功能演示</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 href="http://layer.layui.com/" target="_blank">layer</a>
  7. <a><cite>功能演示</cite></a>
  8. </div>
  9. </div>
  10. <style>
  11. /* 这段样式只是用于演示 */
  12. #LAY-component-layer-list .layui-card-body{padding-top: 15px;}
  13. </style>
  14. <div class="layui-fluid" id="LAY-component-layer-list">
  15. <div class="layui-row layui-col-space15">
  16. <div class="layui-col-md12">
  17. <div class="layui-card demo-component-layer">
  18. <div class="layui-card-header">弹层之美</div>
  19. <div class="layui-card-body">
  20. <blockquote class="layui-elem-quote">
  21. layer 是 layui 中最广为人知的组件,它可以轻松应对 Web 应用开发中的各类复杂的弹出交互。有人说使用 layer 是一种情怀,一旦用上了,就离不开了。有多少人是因为 layer 才选择 layui 的呢,有一种信仰,叫:无条件相信
  22. </blockquote>
  23. </div>
  24. </div>
  25. <div class="layui-card">
  26. <div class="layui-card-header">弹层类型</div>
  27. <div class="layui-card-body">
  28. <div class="layui-btn-container layadmin-layer-demo">
  29. <button class="layui-btn layui-btn-primary" data-type="test1">Alert</button>
  30. <button class="layui-btn layui-btn-primary" data-type="test2">Confirm</button>
  31. <button class="layui-btn layui-btn-primary" data-type="test3">Msg</button>
  32. <button class="layui-btn layui-btn-primary" data-type="test4">Tips</button>
  33. <button class="layui-btn layui-btn-primary" data-type="test5">Page</button>
  34. <button class="layui-btn layui-btn-primary" data-type="test6">Iframe</button>
  35. <button class="layui-btn layui-btn-primary" data-type="test7">Prompt</button>
  36. <button class="layui-btn layui-btn-primary" data-type="test8">Tab</button>
  37. <button class="layui-btn layui-btn-primary" data-type="test9">Photos</button>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="layui-card">
  42. <div class="layui-card-header">常规使用</div>
  43. <div class="layui-card-body">
  44. <div class="layui-btn-container layadmin-layer-demo">
  45. <button class="layui-btn layui-btn-primary" data-type="test10">信息框</button>
  46. <button class="layui-btn layui-btn-primary" data-type="test11">询问层</button>
  47. <button class="layui-btn layui-btn-primary" data-type="test12">提示层</button>
  48. <button class="layui-btn layui-btn-primary" data-type="test13">墨绿深蓝风</button>
  49. <button class="layui-btn layui-btn-primary" data-type="test14">捕获页</button>
  50. <button class="layui-btn layui-btn-primary" data-type="test15">页面层</button>
  51. <button class="layui-btn layui-btn-primary" data-type="test16">自定风格</button>
  52. <button class="layui-btn layui-btn-primary" data-type="test17">tips层1</button>
  53. <button class="layui-btn layui-btn-primary" data-type="test18">tips层2</button>
  54. <button class="layui-btn layui-btn-primary" data-type="test19">iframe层</button>
  55. <button class="layui-btn layui-btn-primary" data-type="test20">iframe窗</button>
  56. <button class="layui-btn layui-btn-primary" data-type="test21">加载层1</button>
  57. <button class="layui-btn layui-btn-primary" data-type="test22">加载层2</button>
  58. <button class="layui-btn layui-btn-primary" data-type="test23">prompt层</button>
  59. <button class="layui-btn layui-btn-primary" data-type="test8">tab层</button>
  60. <button class="layui-btn layui-btn-primary" data-type="test9">相册层</button>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="layui-col-md12">
  66. <div class="layui-card">
  67. <div class="layui-card-header">信息框</div>
  68. <div class="layui-card-body">
  69. <div class="layui-btn-container layadmin-layer-demo">
  70. <button class="layui-btn layui-btn-primary" data-type="test26">例1</button>
  71. <button class="layui-btn layui-btn-primary" data-type="test27">例2</button>
  72. <button class="layui-btn layui-btn-primary" data-type="test28">例3</button>
  73. <button class="layui-btn layui-btn-primary" data-type="test29">例4</button>
  74. <button class="layui-btn layui-btn-primary" data-type="test30">例5</button>
  75. <button class="layui-btn layui-btn-primary" data-type="test31">例6</button>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="layui-col-md12">
  81. <div class="layui-card">
  82. <div class="layui-card-header">页面层与iframe层</div>
  83. <div class="layui-card-body">
  84. <div class="layui-btn-container layadmin-layer-demo">
  85. <button class="layui-btn layui-btn-primary" data-type="test33">自定义页面</button>
  86. <button class="layui-btn layui-btn-primary" data-type="test35" id="LAY_layer_iframe_demo">iframe父子通讯</button>
  87. <button class="layui-btn layui-btn-primary" data-type="test36">禁止iframe滚动条</button>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="layui-col-md12">
  93. <div class="layui-card">
  94. <div class="layui-card-header">加载层</div>
  95. <div class="layui-card-body">
  96. <div class="layui-btn-container layadmin-layer-demo">
  97. <button class="layui-btn layui-btn-primary" data-type="test37">风格1</button>
  98. <button class="layui-btn layui-btn-primary" data-type="test38">风格2</button>
  99. <button class="layui-btn layui-btn-primary" data-type="test39">风格3</button>
  100. <button class="layui-btn layui-btn-primary" data-type="test40">风格4</button>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. <div class="layui-col-md12">
  106. <div class="layui-card">
  107. <div class="layui-card-header">tips层</div>
  108. <div class="layui-card-body">
  109. <div class="layui-btn-container layadmin-layer-demo">
  110. <button class="layui-btn layui-btn-primary" data-type="test41">显示在上</button>
  111. <button class="layui-btn layui-btn-primary" data-type="test42">显示在右</button>
  112. <button class="layui-btn layui-btn-primary" data-type="test43">显示在下</button>
  113. <button class="layui-btn layui-btn-primary" data-type="test44">显示在左</button>
  114. <button class="layui-btn layui-btn-primary" data-type="test45">不销毁上一个tips</button>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="layui-col-md12">
  120. <div class="layui-card">
  121. <div class="layui-card-header">其它示例</div>
  122. <div class="layui-card-body">
  123. <div class="layui-btn-container layadmin-layer-demo">
  124. <button class="layui-btn layui-btn-primary" data-type="test47">最大化弹出</button>
  125. <button class="layui-btn layui-btn-primary" data-type="test48">显示在正上方</button>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <script>
  133. layui.use(['admin', 'layer'], function(){
  134. var $ = layui.$
  135. ,admin = layui.admin
  136. ,element = layui.element
  137. ,layer = layui.layer;
  138. element.render();
  139. /* 触发弹层 */
  140. var active = {
  141. test1: function(){
  142. layer.alert('你好,体验者');
  143. }
  144. ,test2: function(){
  145. layer.confirm('您是如何看待前端开发?', {
  146. btn: ['重要','奇葩'] //按钮
  147. }, function(){
  148. layer.msg('的确很重要', {icon: 1});
  149. }, function(){
  150. layer.msg('也可以这样', {
  151. time: 20000, //20s后自动关闭
  152. btn: ['明白了', '知道了']
  153. });
  154. });
  155. }
  156. ,test3: function(){
  157. layer.msg('玩命提示中');
  158. }
  159. ,test4: function(){
  160. layer.tips('Hi,我是一个提示', this, {tips: 1});
  161. }
  162. ,test5: function(){
  163. layer.open({
  164. title:'页面层'
  165. ,type: 1
  166. //,skin: 'layui-layer-rim'
  167. ,shadeClose: true
  168. ,area: admin.screen() < 2 ? ['80%', '300px'] : ['700px', '500px']
  169. ,content: '<div style="padding: 20px;">放入任意HTML</div>'
  170. });
  171. }
  172. ,test6: function(){
  173. layer.open({
  174. type: 2
  175. ,content: 'http://fly.layui.com/'
  176. ,shadeClose: true
  177. ,area: admin.screen() < 2 ? ['100%', '80%'] : ['375px', '500px']
  178. ,maxmin: true
  179. });
  180. }
  181. ,test7: function(){
  182. layer.prompt({title: '输入任何口令,并确认', formType: 1}, function(pass, index){
  183. layer.close(index);
  184. layer.prompt({title: '随便写点啥,并确认', formType: 2}, function(text, index){
  185. layer.close(index);
  186. layer.msg('演示完毕!您的口令:'+ pass +'<br>您最后写下了:'+text);
  187. });
  188. });
  189. }
  190. ,test8: function(){
  191. layer.tab({
  192. area: admin.screen() < 2 ? ['100%', '80%'] : ['600px', '300px'],
  193. tab: [{
  194. title: 'TAB1',
  195. content: '<div style="padding:20px;">内容1</div>'
  196. }, {
  197. title: 'TAB2',
  198. content: '<div style="padding:20px;">内容2</div>'
  199. }]
  200. });
  201. }
  202. ,test9: function(){
  203. $.getJSON('./json/layer/photos.js', function(json){
  204. layer.photos({
  205. photos: json //格式见API文档手册页
  206. });
  207. });
  208. }
  209. ,test10: function(){
  210. var icon = -1;
  211. (function changeIcon(){
  212. var index = layer.alert('Hi,你好! 点击确认更换图标', {
  213. icon: icon,
  214. shadeClose: true,
  215. title: icon === -1 ? '初体验 - layer '+layer.v : 'icon:'+icon + ' - layer '+layer.v
  216. }, changeIcon);
  217. if(8 === ++icon) layer.close(index);
  218. }());
  219. }
  220. ,test11: function(){
  221. layer.confirm('真的吗?', function(index){
  222. layer.msg('哦')
  223. layer.close(index);
  224. });
  225. }
  226. ,test12: function(){
  227. layer.msg('玩了命提示中');
  228. }
  229. ,test13: function(){
  230. //墨绿深蓝风
  231. layer.alert('墨绿风格,点击确认看深蓝', {
  232. skin: 'layui-layer-molv'
  233. ,closeBtn: 0
  234. }, function(){
  235. layer.alert('偶吧深蓝style', {
  236. skin: 'layui-layer-lan'
  237. ,closeBtn: 0
  238. ,anim: 4
  239. });
  240. });
  241. }
  242. ,test14: function(){
  243. layer.open({
  244. type: 1,
  245. shade: false,
  246. title: false,
  247. content: $('.demo-component-layer'),
  248. cancel: function(){
  249. setTimeout(function(){
  250. layer.tips('捕获就是从页面已经存在的元素上,包裹 layer 的结构,从而弹出显示。是不是比较好玩呢?', '.demo-component-layer', {
  251. tips: 3, time: 5000
  252. });
  253. }, 300);
  254. }
  255. });
  256. }
  257. ,test15: function(){
  258. layer.open({
  259. type: 1,
  260. skin: 'layui-layer-rim',
  261. area: ['420px', '240px'],
  262. content: '<div style="padding: 10px;">任意html内容</div>'
  263. });
  264. }
  265. ,test16: function(){
  266. layer.open({
  267. type: 1,
  268. skin: 'layui-layer-admin',
  269. closeBtn: false,
  270. area: '350px',
  271. anim: 5,
  272. shadeClose: true,
  273. content: '<div style="padding:20px;">即传入skin:"样式名",然后你就可以为所欲为了。你怎么样给她整容都行</div>'
  274. });
  275. }
  276. ,test17: function(){
  277. layer.tips('Hi,我是tips', this, {
  278. tips: 1
  279. });
  280. }
  281. ,test18: function(){
  282. layer.tips('我是另外一个tips,只不过我长得跟之前那位稍有些不一样。', this, {
  283. tips: [3, '#2F9688'],
  284. time: 4000
  285. });
  286. }
  287. ,test19: function(){
  288. layer.open({
  289. type: 2,
  290. title: '贤心博客',
  291. shadeClose: true,
  292. shade: 0.8,
  293. area: ['375px', '500px'],
  294. content: 'http://sentsin.com/'
  295. });
  296. }
  297. ,test20: function(){
  298. layer.open({
  299. type: 2,
  300. title: '百度一下',
  301. shade: false,
  302. maxmin: true,
  303. area: ['90%', '90%'],
  304. content: 'http://www.baidu.com/'
  305. });
  306. }
  307. ,test21: function(){
  308. var ii = layer.load(0, {shade: false});
  309. setTimeout(function(){
  310. layer.close(ii)
  311. }, 3000);
  312. }
  313. ,test22: function(){
  314. var iii = layer.load(1, {
  315. shade: [0.1,'#fff']
  316. });
  317. setTimeout(function(){
  318. layer.close(iii)
  319. }, 3000);
  320. }
  321. ,test23: function(){
  322. layer.prompt({title: '写点什么吧'}, function(value, index){
  323. layer.msg('你写下了:'+ value, {
  324. icon: 6
  325. ,shade: 0.9
  326. }, function(){
  327. layer.close(index);
  328. });
  329. });
  330. }
  331. ,test26: function(){
  332. layer.alert('见到你真的很高兴', {icon: 6});
  333. }
  334. ,test27: function(){
  335. layer.msg('你确定你很帅么?', {
  336. time: 0 //不自动关闭
  337. ,btn: ['必须啊', '丑到爆']
  338. ,yes: function(index){
  339. layer.close(index);
  340. layer.msg('雅蠛蝶 O.o', {
  341. icon: 6
  342. ,time: 0
  343. ,btn: ['嗷','嗷','嗷']
  344. });
  345. }
  346. });
  347. }
  348. ,test28: function(){
  349. layer.msg('这是最常用的吧');
  350. }
  351. ,test29: function(){
  352. layer.msg('并不十分开心。。', {icon: 5});
  353. }
  354. ,test30: function(){
  355. layer.msg('玩命卖萌中', function(){
  356. layer.msg('卖完了');
  357. });
  358. }
  359. ,test31: function(){
  360. layer.confirm('真的删除吗?', function(){
  361. layer.msg('正在删除', {icon: 16}, function(){
  362. layer.msg('成功删除', {icon: 1})
  363. });
  364. });
  365. }
  366. ,test33: function(){
  367. layer.open({
  368. type: 1,
  369. title: false,
  370. closeBtn: 0,
  371. shadeClose: true,
  372. skin: 'yourClass',
  373. content: '<div style="padding: 20px; width: 260px; height: 180px;">自定义HTML内容</div>'
  374. });
  375. }
  376. ,test35: function(){
  377. layer.open({
  378. type: 2,
  379. area: ['700px', '450px'],
  380. fixed: false,
  381. maxmin: true,
  382. content: layui.setter.base + 'views/iframe/layer/iframe.html'
  383. });
  384. }
  385. ,test36: function(){
  386. layer.open({
  387. type: 2,
  388. area: ['360px', '500px'],
  389. skin: 'layui-layer-rim',
  390. content: ['http://sentsin.com/', 'no']
  391. });
  392. }
  393. ,test37: function(){
  394. layer.load();
  395. setTimeout(function(){
  396. layer.closeAll('loading');
  397. }, 2000);
  398. }
  399. ,test38: function(){
  400. layer.load(1);
  401. setTimeout(function(){
  402. layer.closeAll('loading');
  403. }, 2000);
  404. }
  405. ,test39: function(){
  406. layer.load(2);
  407. setTimeout(function(){
  408. layer.closeAll('loading');
  409. }, 2000);
  410. }
  411. ,test40: function(){
  412. layer.msg('加载中', {
  413. icon: 16
  414. ,shade: 0.01
  415. });
  416. }
  417. ,test41: function(){
  418. layer.tips('上', this, {
  419. tips: [1, '#000']
  420. });
  421. }
  422. ,test42: function(){
  423. layer.tips('默认就是向右的,3秒后关闭', this);
  424. }
  425. ,test43: function(){
  426. layer.tips('下', this, {
  427. tips: 3
  428. });
  429. }
  430. ,test44: function(){
  431. layer.tips('在很久很久以前,在很久很久以前,在很久很久以前……', this, {
  432. tips: [4, '#78BA32']
  433. });
  434. }
  435. ,test45: function(){
  436. layer.tips('不会销毁之前的', this, {tipsMore: true});
  437. }
  438. ,test47: function(){
  439. var index = layer.open({
  440. type: 2,
  441. content: 'http://baidu.com',
  442. area: ['300px', '300px'],
  443. maxmin: true
  444. });
  445. layer.full(index);
  446. }
  447. ,test48: function(){
  448. layer.msg('灵活运用 offset', {
  449. offset: 't',
  450. anim: 6
  451. });
  452. }
  453. };
  454. $('#LAY-component-layer-list .layadmin-layer-demo .layui-btn').on('click', function(){
  455. var type = $(this).data('type');
  456. active[type] && active[type].call(this);
  457. });
  458. });
  459. </script>