colorpicker.html 16 KB

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