special-demo.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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-special-demo .layui-card-body{padding-top: 15px;}
  13. </style>
  14. <div class="layui-fluid" id="LAY-component-layer-special-demo">
  15. <div class="layui-row layui-col-space15">
  16. <div class="layui-col-md12">
  17. <div class="layui-card">
  18. <div class="layui-card-header">场景</div>
  19. <div class="layui-card-body">
  20. <div class="layui-btn-container layadmin-layer-demo">
  21. <button data-method="setTop" class="layui-btn layui-btn-primary">多窗口模式,层叠置顶</button>
  22. <button data-method="confirmTrans" class="layui-btn layui-btn-primary">配置一个透明的询问框</button>
  23. <button data-method="notice" class="layui-btn layui-btn-primary">示范一个公告层</button>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="layui-col-md12">
  29. <div class="layui-card">
  30. <div class="layui-card-header">坐标</div>
  31. <div class="layui-card-body">
  32. <div class="layui-btn-container layadmin-layer-demo">
  33. <button data-method="offset" data-type="t" class="layui-btn layui-btn-primary">上弹出</button>
  34. <button data-method="offset" data-type="r" class="layui-btn layui-btn-primary">右弹出</button>
  35. <button data-method="offset" data-type="b" class="layui-btn layui-btn-primary">下弹出</button>
  36. <button data-method="offset" data-type="l" class="layui-btn layui-btn-primary">左弹出</button>
  37. <button data-method="offset" data-type="lt" class="layui-btn layui-btn-primary">左上弹出</button>
  38. <button data-method="offset" data-type="lb" class="layui-btn layui-btn-primary">左下弹出</button>
  39. <button data-method="offset" data-type="rt" class="layui-btn layui-btn-primary">右上弹出</button>
  40. <button data-method="offset" data-type="rb" class="layui-btn layui-btn-primary">右下弹出</button>
  41. <button data-method="offset" data-type="auto" class="layui-btn layui-btn-primary">居中弹出</button>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <script>
  49. layui.use(['admin'], function(){
  50. var $ = layui.$
  51. ,admin = layui.admin
  52. ,element = layui.element
  53. ,router = layui.router();
  54. element.render();
  55. var active = {
  56. setTop: function(){
  57. var that = this;
  58. layer.open({
  59. type: 1
  60. ,title: '当你选择该窗体时,即会在最顶端'
  61. ,area: ['390px', '260px']
  62. ,shade: 0
  63. ,maxmin: true
  64. ,offset: [
  65. Math.random()*($(window).height()-300)
  66. ,Math.random()*($(window).width()-390)
  67. ]
  68. ,content: '<div style="padding: 20px;">当你的页面有很多很多layer窗口,你需要像Window窗体那样,点击某个窗口,该窗体就置顶在上面,那么layer.setTop()可以来轻松实现。它采用巧妙的逻辑,以使这种置顶的性能达到最优。</div>'
  69. ,btn: ['继续弹出', '全部关闭']
  70. ,yes: function(){
  71. $(that).click();
  72. }
  73. ,btn2: function(){
  74. layer.closeAll();
  75. }
  76. ,zIndex: layer.zIndex
  77. ,success: function(layero){
  78. layer.setTop(layero);
  79. }
  80. });
  81. }
  82. ,confirmTrans: function(){
  83. layer.closeAll();
  84. layer.msg('大部分参数都是可以公用的<br>合理搭配,展示不一样的风格', {
  85. time: 20*1000,
  86. btn: ['明白了', '知道了', '哦']
  87. });
  88. }
  89. ,notice: function(){
  90. layer.closeAll();
  91. layer.open({
  92. type: 1
  93. ,title: false
  94. ,closeBtn: false
  95. ,area: '300px;'
  96. ,shade: 0.8
  97. ,id: 'LAY_layuipro'
  98. ,btn: ['火速围观', '残忍拒绝']
  99. ,btnAlign: 'c'
  100. ,moveType: 1 //拖拽模式,0或者1
  101. ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗?亲!<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块,由于其用户基数较大,所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块,但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
  102. ,success: function(layero){
  103. var btn = layero.find('.layui-layer-btn');
  104. btn.find('.layui-layer-btn0').attr({
  105. href: 'http://www.layui.com/'
  106. ,target: '_blank'
  107. });
  108. }
  109. });
  110. }
  111. ,offset: function(othis){
  112. var type = othis.data('type')
  113. ,text = othis.text();
  114. layer.open({
  115. type: 1
  116. ,offset: type
  117. ,id: 'layerDemo'+type
  118. ,content: '<div style="padding: 20px 100px;">'+ text +'</div>'
  119. ,btn: '关闭全部'
  120. ,btnAlign: 'c'
  121. ,shade: 0
  122. ,yes: function(){
  123. layer.closeAll();
  124. }
  125. });
  126. }
  127. };
  128. $('#LAY-component-layer-special-demo .layadmin-layer-demo .layui-btn').on('click', function(){
  129. var othis = $(this), method = othis.data('method');
  130. active[method] ? active[method].call(this, othis) : '';
  131. });
  132. });
  133. </script>