博客列表 >初识LayUI

初识LayUI

海阔天空
海阔天空原创
2020年06月03日 16:50:12713浏览

LayUI

Layui(谐音:类UI) 是一款采用自身模块规范编写的前端 UI 框架,遵循原生 HTML/CSS/JS 的书写与组织形式。Layui更多是为服务端程序员量身定做,无需涉足各种前端工具的复杂配置,只需面对浏览器本身,让一切所需要的元素与交互,从这里信手拈来。

效果图如下:

代码如下:

  1. //demo1.html
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>LayUI管理平台</title>
  8. <link rel="stylesheet" href="/layui/css/layui.css" />
  9. <script src="/layui/layui.js"></script>
  10. <style>
  11. .container {
  12. display: flex;
  13. width: 100vw;
  14. height: 850px;
  15. box-sizing: border-box;
  16. }
  17. iframe{
  18. width:90%;
  19. height:95%;
  20. margin-top: 30px;
  21. margin-left: 60px;
  22. }
  23. .iframe{
  24. width:100%;
  25. height:100%;
  26. }
  27. #nav {
  28. background-color: #000;
  29. color: white;
  30. height: 50px;
  31. line-height: 50px;
  32. padding-left: 20px;
  33. display: flex;
  34. font-size: 18px;
  35. font-weight: 550;
  36. }
  37. #nav span:nth-of-type(2) {
  38. color: rgb(206, 134, 134);
  39. margin-left: auto;
  40. padding: 0 3px;
  41. font-size: 20px;
  42. }
  43. #nav span:nth-of-type(3) {
  44. color: rgb(206, 134, 134);
  45. padding-right: 20px;
  46. }
  47. #nav span:last-of-type {
  48. padding-right: 20px;
  49. }
  50. #nav span:last-of-type a {
  51. color: white;
  52. }
  53. .leftmenu {
  54. width: 200px;
  55. padding: 30px 30px;
  56. }
  57. .content{
  58. background-color: #fff;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <!-- header -->
  64. <div id="nav">
  65. <span>LayUI后台管理系统</span>
  66. <span class="layui-icon layui-icon-username"></span>
  67. <span>admin</span>
  68. <span><a href="">退出</a></span>
  69. </div>
  70. <!-- 工作区 -->
  71. <div class="container">
  72. <!-- 左侧菜单 -->
  73. <div class="layui-collapse leftmenu" lay-accordion>
  74. <div class="layui-colla-item">
  75. <h2 class="layui-colla-title">杜甫</h2>
  76. <div class="layui-colla-content content">唐代大诗人,尊称诗圣</div>
  77. </div>
  78. <div class="layui-colla-item">
  79. <h2 class="layui-colla-title">李清照</h2>
  80. <div class="layui-colla-content content">宋代大词人</div>
  81. </div>
  82. <div class="layui-colla-item">
  83. <h2 class="layui-colla-title">鲁迅</h2>
  84. <div class="layui-colla-content content" >近代大文豪</div>
  85. </div>
  86. </div>
  87. <!-- 右侧工作区 -->
  88. <div class="iframe">
  89. <iframe frameborder="none" src="main.html"></iframe>
  90. </div>
  91. </div>
  92. <script>
  93. //注意:折叠面板 依赖 element 模块,否则无法进行功能性操作
  94. layui.use("element", function () {
  95. var element = layui.element;
  96. //…
  97. });
  98. </script>
  99. </body>
  100. </html>
  101. //main.html
  102. <!DOCTYPE html>
  103. <html lang="en">
  104. <head>
  105. <meta charset="UTF-8">
  106. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  107. <title>Document</title>
  108. <link rel="stylesheet" href="/layui/css/layui.css" />
  109. <script src="/layui/layui.js"></script>
  110. </head>
  111. <body>
  112. <form class="layui-form layui-form-pane" action="">
  113. <div class="layui-form-item">
  114. <label class="layui-form-label">输入框</label>
  115. <div class="layui-input-block">
  116. <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
  117. </div>
  118. </div>
  119. <div class="layui-form-item">
  120. <label class="layui-form-label">密码框</label>
  121. <div class="layui-input-inline">
  122. <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
  123. </div>
  124. <div class="layui-form-mid layui-word-aux">辅助文字</div>
  125. </div>
  126. <div class="layui-form-item">
  127. <label class="layui-form-label">选择框</label>
  128. <div class="layui-input-inline">
  129. <select name="city" lay-verify="required">
  130. <option value=""></option>
  131. <option value="0">北京</option>
  132. <option value="1">上海</option>
  133. <option value="2">广州</option>
  134. <option value="3">深圳</option>
  135. <option value="4">杭州</option>
  136. </select>
  137. </div>
  138. </div>
  139. <div class="layui-form-item" pane>
  140. <label class="layui-form-label">复选框</label>
  141. <div class="layui-input-block">
  142. <input type="checkbox" name="like[write]" title="写作">
  143. <input type="checkbox" name="like[read]" title="阅读" checked>
  144. <input type="checkbox" name="like[dai]" title="发呆"lay-skin="primary">
  145. </div>
  146. </div>
  147. <div class="layui-form-item" pane>
  148. <label class="layui-form-label">开关</label>
  149. <div class="layui-input-block">
  150. <input type="checkbox" name="switch" lay-skin="switch" lay-text="开启|关闭">
  151. </div>
  152. </div>
  153. <div class="layui-form-item" pane>
  154. <label class="layui-form-label">单选框</label>
  155. <div class="layui-input-block">
  156. <input type="radio" name="sex" value="男" title="男">
  157. <input type="radio" name="sex" value="女" title="女" checked>
  158. </div>
  159. </div>
  160. <div class="layui-form-item layui-form-text">
  161. <label class="layui-form-label">文本域</label>
  162. <div class="layui-input-block">
  163. <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
  164. </div>
  165. </div>
  166. <div class="layui-form-item">
  167. <div class="layui-input-block">
  168. <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
  169. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  170. </div>
  171. </div>
  172. </form>
  173. <script>
  174. //Demo
  175. layui.use('form', function(){
  176. var form = layui.form;
  177. //监听提交
  178. form.on('submit(formDemo)', function(data){
  179. layer.msg(JSON.stringify(data.field));
  180. return false;
  181. });
  182. });
  183. </script>
  184. </body>
  185. </html>

总结:初次接触Layui,听了老师的讲解,感觉上手相对不是太难,实现效果不错,效率较高。
1、下载并安装Layui。
2、阅读了Layui手册。
3、初步掌握了界面的实现,事件的响应等还需要今后的学习逐步掌握。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议