popover.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>汽泡组件</title>
  8. <link rel="stylesheet" href="../../component/pear/css/pear.css" />
  9. </head>
  10. <body class="pear-container">
  11. <div>
  12. <div class="layui-row layui-col-space10">
  13. <div class="layui-col-md12">
  14. <div class="layui-card">
  15. <div class="layui-card-header">开发环境</div>
  16. <div class="layui-card-body">
  17. popover 用于 汽泡显示 场景
  18. </div>
  19. </div>
  20. </div>
  21. <div class="layui-col-md12">
  22. <div class="layui-collapse">
  23. <div class="layui-colla-item">
  24. <h2 class="layui-colla-title">显示代码</h2>
  25. <div class="layui-colla-content">
  26. <pre class="layui-code" lay-encode="true">
  27. &lt;link rel="stylesheet" href="component/pear/css/pear.css" />
  28. &lt;script src="component/layui/layui.js">&lt;/script>
  29. &lt;script src="component/pear/pear.js">&lt;/script>
  30. </pre>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="layui-col-md12">
  36. <div class="layui-card">
  37. <div class="layui-card-header">汽泡控制</div>
  38. <div class="layui-card-body">
  39. <button class="popover-show pear-btn pear-btn-primary">显示</button>
  40. <button class="popover-hide pear-btn pear-btn-success">隐藏</button>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="layui-col-md12">
  45. <div class="layui-collapse">
  46. <div class="layui-colla-item">
  47. <h2 class="layui-colla-title">显示代码</h2>
  48. <div class="layui-colla-content">
  49. <pre class="layui-code" lay-encode="true">
  50. layui.use(['popover', 'jquery', 'layer', 'code'], function() {
  51. var popover = layui.popover;
  52. popover.show('#el1');
  53. popover.hide('#el1'); //或 $('#el1').webuiPopover('hide');
  54. })
  55. </pre>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="layui-col-md12">
  61. <div class="layui-card">
  62. <div class="layui-card-header">
  63. 不同方式
  64. </div>
  65. <div class="layui-card-body">
  66. <button class="toast-top-left-btn pear-btn" id="el1">手动</button>
  67. <button class="toast-top-center-btn pear-btn" id="el2">回调</button>
  68. <button class="toast-top-center-btn pear-btn" id="el3">iframe</button>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="layui-col-md12">
  73. <div class="layui-collapse">
  74. <div class="layui-colla-item">
  75. <h2 class="layui-colla-title">显示代码</h2>
  76. <div class="layui-colla-content">
  77. <pre class="layui-code" lay-encode="true">
  78. layui.use(['toast', 'jquery', 'layer', 'code'], function() {
  79. var popover = layui.popover;
  80. popover.create('#el1',{title:' hello popover-manual',content:'这里显示内容',trigger:'manual',placement:'auto',
  81. animation:'pop',
  82. closeable:true,
  83. delay: {
  84. //show and hide delay time of the popover, works only when trigger is 'hover',the value can be number or object
  85. show: null,
  86. hide: 100
  87. },
  88. opacity:0.98,
  89. type:'html',//content type, values:'html','iframe','async'
  90. });
  91. })
  92. </pre>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="layui-col-md12">
  98. <div class="layui-card">
  99. <div class="layui-card-header">
  100. 隐藏
  101. </div>
  102. <div class="layui-card-body">
  103. <button class="pear-btn" id="closeAll">隐藏全部</button>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="layui-col-md12">
  108. <div class="layui-collapse">
  109. <div class="layui-colla-item">
  110. <h2 class="layui-colla-title">显示代码</h2>
  111. <div class="layui-colla-content">
  112. <pre class="layui-code" lay-encode="true">
  113. layui.use(['popover', 'jquery', 'layer', 'code'], function() {
  114. var popover = layui.popover;
  115. popover.hideAll();
  116. })
  117. </pre>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </body>
  125. <script src="../../component/layui/layui.js"></script>
  126. <script src="../../component/pear/pear.js"></script>
  127. <script>
  128. layui.use(['popover', 'jquery', 'layer', 'code', 'element'], function() {
  129. var layer = layui.layer;
  130. var $ = layui.jquery;
  131. var popover = layui.popover;
  132. var element = layui.element;
  133. layui.code();
  134. $(".popover-show").click(function(e) {
  135. popover.show('#el1');
  136. })
  137. $("#el1").click(function(e) {
  138. popover.show('#el1');
  139. })
  140. $(".popover-hide").click(function(e){
  141. popover.hide('#el1'); //或 $('#el1').webuiPopover('hide');
  142. })
  143. $("#closeAll").click(function(e){
  144. popover.hideAll();
  145. });
  146. //html 事件 手动
  147. //用法参照 https://github.com/sandywalker/webui-popover
  148. //增加功能 opacity [0,1] 可指定 popover 透明度
  149. popover.create('#el1',{title:' hello popover-manual',content:'这里显示内容',trigger:'manual',
  150. animation:'pop',
  151. closeable:true,
  152. placement:'auto',
  153. delay: {
  154. //show and hide delay time of the popover, works only when trigger is 'hover',the value can be number or object
  155. show: null,
  156. hide: 100
  157. },
  158. opacity:0.98,
  159. type:'html',//content type, values:'html','iframe','async'
  160. })
  161. //html 事件 hover
  162. popover.create('#el2',{title:' hello popover-hover',content:'<div class="layui-tab layui-tab-brief" lay-filter="test">\n' +
  163. ' <ul class="layui-tab-title">\n' +
  164. ' <li class="layui-this" lay-id="11">网站设置</li>\n' +
  165. ' <li lay-id="22">用户管理</li>\n' +
  166. ' <li lay-id="33">权限分配</li>\n' +
  167. ' <li lay-id="44">商品管理</li>\n' +
  168. ' <li lay-id="55">订单管理</li>\n' +
  169. ' </ul>\n' +
  170. ' <div class="layui-tab-content" style="height: 100px;">\n' +
  171. ' <div class="layui-tab-item layui-show">内容不一样是要有,因为你可以获得 tab 事件</div>\n' +
  172. ' <div class="layui-tab-item">内容2</div>\n' +
  173. ' <div class="layui-tab-item">内容3</div>\n' +
  174. ' <div class="layui-tab-item">内容4</div>\n' +
  175. ' <div class="layui-tab-item">内容5</div>\n' +
  176. ' </div>\n' +
  177. '</div> ',trigger:'hover',
  178. animation:'pop',
  179. delay: {
  180. //show and hide delay time of the popover, works only when trigger is 'hover',the value can be number or object
  181. show: null,
  182. hide: 100
  183. },
  184. placement:'top-right',
  185. opacity:0.98,
  186. onShow: function($element) {
  187. //console.log("onShow",$element);
  188. element.on('tab(test)', function(elem){
  189. location.hash = 'test='+ $(this).attr('lay-id');
  190. console.log(location.hash);
  191. })
  192. },
  193. });
  194. popover.create('#el3',{title:' hello popover-iframe',trigger:'hover',
  195. animation:'pop',
  196. closeable:true,
  197. placement:'auto',
  198. delay: {
  199. //show and hide delay time of the popover, works only when trigger is 'hover',the value can be number or object
  200. show: null,
  201. hide: 100
  202. },
  203. opacity:0.98,
  204. type:'iframe',//content type, values:'html','iframe','async'
  205. url:'http://cn.bing.com/',
  206. width:500,
  207. height:400
  208. })
  209. });
  210. </script>
  211. </html>