index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>jQuery MiniColors一款简单的颜色选择器-www.daimajiayuan.com</title>
  5. <meta charset="utf-8">
  6. <!-- jQuery -->
  7. <script src="jquery.min.js"></script>
  8. <!-- Bootstrap 3 -->
  9. <link rel="stylesheet" href="bootstrap.min.css">
  10. <script src="bootstrap.min.js"></script>
  11. <!-- MiniColors -->
  12. <script src="jquery.minicolors.js"></script>
  13. <link rel="stylesheet" href="jquery.minicolors.css">
  14. <style>
  15. dl {
  16. margin: 20px 0;
  17. }
  18. dt {
  19. font-size: 120%;
  20. }
  21. dd {
  22. padding: 10px 20px 20px 20px;
  23. }
  24. dd:last-child {
  25. border-bottom: none;
  26. }
  27. code {
  28. color: black;
  29. border: none;
  30. background: rgba(128, 128, 128, .1);
  31. }
  32. pre {
  33. background: #f8f8f8;
  34. border: none;
  35. color: #333;
  36. padding: 20px;
  37. }
  38. h2 {
  39. margin-top: 50px;
  40. }
  41. h3 {
  42. color: #aaa;
  43. }
  44. </style>
  45. <script>
  46. $(document).ready( function() {
  47. $('.demo').each( function() {
  48. //
  49. // Dear reader, it's actually very easy to initialize MiniColors. For example:
  50. //
  51. // $(selector).minicolors();
  52. //
  53. // The way I've done it below is just for the demo, so don't get confused
  54. // by it. Also, data- attributes aren't supported at this time...they're
  55. // only used for this demo.
  56. //
  57. $(this).minicolors({
  58. control: $(this).attr('data-control') || 'hue',
  59. defaultValue: $(this).attr('data-defaultValue') || '',
  60. inline: $(this).attr('data-inline') === 'true',
  61. letterCase: $(this).attr('data-letterCase') || 'lowercase',
  62. opacity: $(this).attr('data-opacity'),
  63. position: $(this).attr('data-position') || 'bottom left',
  64. change: function(hex, opacity) {
  65. if( !hex ) return;
  66. if( opacity ) hex += ', ' + opacity;
  67. try {
  68. console.log(hex);
  69. } catch(e) {}
  70. },
  71. theme: 'bootstrap'
  72. });
  73. });
  74. });
  75. </script>
  76. </head>
  77. <body>
  78. <div class="row" style="margin: 40px 40px;">
  79. <div class="col-12">
  80. <!-- Intro -->
  81. <div id="intro" class="jumbotron">
  82. <h1>jQuery MiniColors 2.1</h1>
  83. <p class="text-muted">
  84. Now with Bootstrap 3 support!
  85. </p>
  86. </div>
  87. <!-- Contents -->
  88. <h2 id="contents">Contents</h2>
  89. <ul>
  90. <li><a href="#download">Download</a></li>
  91. <li><a href="#demos">Demos</a></li>
  92. <li><a href="#api">API</a>
  93. <ul>
  94. <li><a href="#settings">Settings</a></li>
  95. <li><a href="#methods">Methods</a></li>
  96. <li><a href="#events">Events</a></li>
  97. </ul>
  98. </li>
  99. <li><a href="#license">License</a></li>
  100. </ul>
  101. <!-- Download -->
  102. <!-- Demos -->
  103. <h2 id="demos">Demos</h2>
  104. <p>
  105. <a href="without-bootstrap.html" class="btn btn-primary">View Demo Without Bootstrap</a>
  106. </p>
  107. <!-- Control types -->
  108. <h3>Control Types</h3>
  109. <div class="well">
  110. <div class="row">
  111. <div class="col-lg-4 col-sm-4 col-12">
  112. <div class="form-group">
  113. <label for="hue-demo">Hue (default)</label>
  114. <input type="text" id="hue-demo" class="form-control demo" data-control="hue" value="#ff6161">
  115. </div>
  116. <div class="form-group">
  117. <label for="saturation-demo">Saturation</label>
  118. <input type="text" id="saturation-demo" class="form-control demo" data-control="saturation" value="#0088cc">
  119. </div>
  120. </div>
  121. <div class="col-lg-4 col-sm-4 col-12">
  122. <div class="form-group">
  123. <label for="brightness-demo">Brightness</label>
  124. <input type="text" id="brightness-demo" class="form-control demo" data-control="brightness" value="#00ffff">
  125. </div>
  126. <div class="form-group">
  127. <label for="wheel-demo">Wheel</label>
  128. <input type="text" id="wheel-demo" class="form-control demo" data-control="wheel" value="#ff99ee">
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <!-- Input modes -->
  134. <h3>Input Modes</h3>
  135. <div class="well">
  136. <div class="row">
  137. <div class="col-lg-4 col-sm-4 col-12">
  138. <div class="form-group">
  139. <label for="text-field">Text field</label>
  140. <br>
  141. <input type="text" id="text-field" class="form-control demo" value="#70c24a">
  142. </div>
  143. <div class="form-group">
  144. <label for="hidden-input">Hidden Input</label>
  145. <br>
  146. <input type="hidden" id="hidden-input" class="demo" value="#db913d">
  147. </div>
  148. </div>
  149. <div class="col-lg-4 col-sm-4 col-12">
  150. <div class="form-group">
  151. <label for="inline">Inline</label>
  152. <br>
  153. <input type="text" id="inline" class="form-control demo" data-inline="true" value="#4fc8db">
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- Positions -->
  159. <h3>Positions</h3>
  160. <div class="well">
  161. <p>
  162. Valid positions include <code>bottom left</code>, <code>bottom right</code>, <code>top
  163. left</code>, and <code>top right</code>.
  164. </p>
  165. <div class="row">
  166. <div class="col-lg-4 col-sm-4 col-12">
  167. <div class="form-group">
  168. <label for="position-bottom-left">bottom left (default)</label>
  169. <input type="text" id="position-bottom-left" class="form-control demo" data-position="bottom left" value="#0088cc">
  170. </div>
  171. <div class="form-group">
  172. <label for="position-top-left">top left</label>
  173. <input type="text" id="position-top-left" class="form-control demo" data-position="top left" value="#0088cc">
  174. </div>
  175. </div>
  176. <div class="col-lg-4 col-sm-4 col-12">
  177. <div class="form-group">
  178. <label for="position-bottom-right">bottom right</label>
  179. <input type="text" id="position-bottom-right" class="form-control demo" data-position="bottom right" value="#0088cc">
  180. </div>
  181. <div class="form-group">
  182. <label for="position-top-right">top right</label>
  183. <input type="text" id="position-top-right" class="form-control demo" data-position="top right" value="#0088cc">
  184. </div>
  185. </div>
  186. <div class="col-lg-4 col-sm-4 col-12">
  187. </div>
  188. </div>
  189. </div>
  190. <!-- and more -->
  191. <h3>&hellip;and more!</h3>
  192. <div class="well">
  193. <div class="row">
  194. <div class="col-lg-4 col-sm-4 col-12">
  195. <div class="form-group">
  196. <label for="opacity">Opacity</label>
  197. <br>
  198. <input type="text" id="opacity" class="form-control demo" data-opacity=".5" value="#766fa8">
  199. <span class="help-block">
  200. Opacity can be assigned by including the <code>data-opacity</code> attribute
  201. or by setting the <code>opacity</code> option to <code>true</code>.
  202. </span>
  203. </div>
  204. </div>
  205. <div class="col-lg-4 col-sm-4 col-12">
  206. <div class="form-group">
  207. <label for="default-value">Default Value</label>
  208. <br>
  209. <input type="text" id="default-value" class="form-control demo" data-defaultValue="#ff6600">
  210. <span class="help-block">
  211. This field has a default value assigned to it, so it will never be empty.
  212. </span>
  213. </div>
  214. </div>
  215. <div class="col-lg-4 col-sm-4 col-12">
  216. <div class="form-group">
  217. <label for="letter-case">Letter Case</label>
  218. <br>
  219. <input type="text" id="letter-case" class="form-control demo" data-letterCase="uppercase" value="#abcdef">
  220. <span class="help-block">
  221. This field will always be uppercase.
  222. </span>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. <!-- API -->
  228. <h2 id="api">API</h2>
  229. <!-- Instantiation -->
  230. <h3 id="instantiation">Instantiation</h3>
  231. <p>
  232. Instantiate like any other jQuery plugin:
  233. </p>
  234. <pre>$('INPUT.minicolors').minicolors(settings);</pre>
  235. <!-- Settings -->
  236. <h3 id="settings">Settings</h3>
  237. <p>
  238. Default settings are as follows:
  239. </p>
  240. <pre>
  241. $.minicolors = {
  242. defaults: {
  243. animationSpeed: 50,
  244. animationEasing: 'swing',
  245. change: null,
  246. changeDelay: 0,
  247. control: 'hue',
  248. defaultValue: '',
  249. hide: null,
  250. hideSpeed: 100,
  251. inline: false,
  252. letterCase: 'lowercase',
  253. opacity: false,
  254. position: 'bottom left',
  255. show: null,
  256. showSpeed: 100,
  257. theme: 'default'
  258. }
  259. };
  260. </pre>
  261. <p>
  262. For convenience, you can change default settings globally by assigning new values:
  263. </p>
  264. <pre>
  265. $.minicolors.defaults.changeDelay = 200;
  266. </pre>
  267. <p>
  268. To change multiple properties at once, use <code>$.extend()</code>:
  269. </p>
  270. <pre>
  271. $.minicolors.defaults = $.extend($.minicolors.defaults, {
  272. changeDelay: 200,
  273. letterCase: 'uppercase',
  274. theme: 'bootstrap'
  275. });
  276. </pre>
  277. <p class="alert alert-warning">
  278. <strong>Note:</strong> Changing default settings will <em>not</em> affect controls that
  279. are already initialized.
  280. </p>
  281. <dl>
  282. <dt>animationSpeed</dt>
  283. <dd>
  284. <p>
  285. The animation speed of the sliders when the user taps or clicks a new color. Set to
  286. <code>0</code> for no animation.
  287. </p>
  288. </dd>
  289. <dt>animationEasing</dt>
  290. <dd>
  291. <p>
  292. The easing to use when animating the sliders.
  293. </p>
  294. </dd>
  295. <dt>changeDelay</dt>
  296. <dd>
  297. <p>
  298. The time, in milliseconds, to defer the <code>change</code> event from firing while
  299. the user makes a selection. This is useful for preventing the <code>change</code> event
  300. from firing frequently as the user drags the color picker around.
  301. </p>
  302. <p>
  303. The default value is <code>0</code> (no delay). If your <code>change</code> callback
  304. features something resource-intensive (such as an AJAX request), you’ll probably want
  305. to set this to at least <code>200</code>.
  306. </p>
  307. </dd>
  308. <dt>control</dt>
  309. <dd>
  310. <p>
  311. Determines the type of control. Valid options are <code>hue</code>, <code>brightness</code>,
  312. <code>saturation</code>, and <code>wheel</code>.
  313. </p>
  314. </dd>
  315. <dt>defaultValue</dt>
  316. <dd>
  317. <p>
  318. To force a default color, set this to a valid hex string. When the user clears the
  319. control, it will revert to this color.
  320. </p>
  321. </dd>
  322. <dt>hideSpeed &amp; showSpeed</dt>
  323. <dd>
  324. <p>
  325. The speed at which to hide and show the color picker.
  326. </p>
  327. </dd>
  328. <dt>inline</dt>
  329. <dd>
  330. <p>
  331. Set to <code>true</code> to force the color picker to appear inline.
  332. </p>
  333. </dd>
  334. <dt>letterCase</dt>
  335. <dd>
  336. <p>
  337. Determines the letter case of the hex code value. Valid options are <code>uppercase</code>
  338. or <code>lowercase</code>.
  339. </p>
  340. </dd>
  341. <dt>opacity</dt>
  342. <dd>
  343. <p>
  344. Set to <code>true</code> to enable the opacity slider. (Use the input element's
  345. <code>data-opacity</code> attribute to set a preset value.)
  346. </p>
  347. </dd>
  348. <dt>position</dt>
  349. <dd>
  350. <p>
  351. Sets the position of the dropdown. Valid options are <code>bottom left</code>,
  352. <code>bottom right</code>, <code>top left</code>, and <code>top right</code>.
  353. </p>
  354. <p class="alert alert-warning">
  355. The <code>swatchPosition</code> setting has been removed in version 2.1. The position
  356. of the swatch is now determined by <code>position</code>.
  357. </p>
  358. </dd>
  359. <dt>theme</dt>
  360. <dd>
  361. <p>
  362. A string containing the name of the custom theme to be applied. In your CSS, prefix
  363. your selectors like this:
  364. </p>
  365. <pre>
  366. .minicolors-theme-yourThemeName { ... }
  367. </pre>
  368. <p>
  369. If you are using the default theme, you will probably need to adjust the swatch
  370. styles depending on your existing stylesheet rules. Version 2.1 removes as much
  371. styling on the <code>input</code> element as possible, which means it’s up to
  372. you to adjust your CSS to make sure the swatch aligns properly.
  373. </p>
  374. <p>
  375. To adjust the swatch, override these styles:
  376. </p>
  377. <pre>
  378. .minicolors-theme-default .minicolors-swatch {
  379. top: 5px;
  380. left: 5px;
  381. width: 18px;
  382. height: 18px;
  383. }
  384. .minicolors-theme-default.minicolors-position-right .minicolors-swatch {
  385. left: auto;
  386. right: 5px;
  387. }
  388. </pre>
  389. </div>
  390. </dd>
  391. </dl>
  392. <!-- Methods -->
  393. <h3 id="methods">Methods</h3>
  394. <p>Use this syntax for calling methods:</p>
  395. <pre>$(<em>selector</em>).minicolors('method', <em>[data]</em>);</pre>
  396. <dl>
  397. <dt>create</dt>
  398. <dd>
  399. <p>
  400. Initializes the control for all items matching your selector. This is the default
  401. method, so <code>data</code> may be passed in as the only argument.
  402. </p>
  403. <p>
  404. To set a preset color value, populate the <code>value</code> attribute of the original
  405. input element.
  406. </p>
  407. </dd>
  408. <dt>destroy</dt>
  409. <dd>
  410. <p>
  411. Returns the <em>input</em> element to its original, uninitialized state.
  412. </p>
  413. </dd>
  414. <dt>opacity</dt>
  415. <dd>
  416. <p>
  417. Gets or sets a control's opacity level. To use this method as a setter, pass data in
  418. as a value between 0 and 1. (You can also obtain this value by checking the input
  419. element's <code>data-opacity</code> attribute.)
  420. </p>
  421. <p>
  422. To set a preset opacity value, populate the <code>data-opacity</code> attribute of the
  423. original input element.
  424. </p>
  425. </dd>
  426. <dt>rgbObject</dt>
  427. <dd>
  428. <p>
  429. Returns an object containing red, green, blue, and alpha properties that correspond to
  430. the control's current value. Example:
  431. </p>
  432. <pre>{ r: 0, g: 82, b: 148, a: 0.75 }</pre>
  433. </dd>
  434. <dt>rgbString &amp; rgbaString</dt>
  435. <dd>
  436. <p>
  437. Returns an RGB or RGBA string suitable for use in your CSS. Examples:
  438. </p>
  439. <pre>
  440. rgb(0, 82, 148)
  441. rgba(0, 82, 148, .75)
  442. </pre>
  443. </dd>
  444. <dt>settings</dt>
  445. <dd>
  446. <p>
  447. Gets or sets a control's settings. If new settings are passed in, the control will
  448. destroy and re-initialize itself with any new settings overriding the old ones.
  449. </p>
  450. </dd>
  451. <dt>value</dt>
  452. <dd>
  453. <p>
  454. Gets or sets a control's color value. To use this method as a setter, pass
  455. <code>data</code> in as a hex value. (You can also obtain this value by checking the
  456. input element's <code>value</code> attribute.)
  457. </p>
  458. </dd>
  459. </dl>
  460. <!-- Events -->
  461. <h3 id="events">Events</h3>
  462. <dl>
  463. <dt>change</dt>
  464. <dd>
  465. <p>Fires when the value of the color picker changes. The <code>this</code> keyword will reference the original input element.
  466. <pre>
  467. $(<em>selector</em>).minicolors({
  468. change: function(hex, opacity) {
  469. console.log(hex + ' - ' + opacity);
  470. }
  471. });
  472. </pre>
  473. <p class="alert alert-warning">
  474. <strong>Warning!</strong> This event will fire a lot when the user drags the
  475. color picker around. Use the <code>changeDelay</code> setting to reduce its
  476. frequency.
  477. </p>
  478. </dd>
  479. <dt>hide</dt>
  480. <dd>
  481. <p>
  482. Fires when the color picker is hidden. The <code>this</code> keyword will reference
  483. the original input element.
  484. </p>
  485. <pre>
  486. $(<em>selector</em>).minicolors({
  487. hide: function() {
  488. console.log('Hide event triggered!');
  489. }
  490. });
  491. </pre>
  492. </dd>
  493. <dt>show</dt>
  494. <dd>
  495. <p>
  496. Fires when the color picker is shown. The <code>this</code> keyword will reference
  497. the original input element.
  498. </p>
  499. <pre>
  500. $(<em>selector</em>).minicolors({
  501. show: function() {
  502. console.log('Show event triggered!');
  503. }
  504. });
  505. </pre>
  506. </dd>
  507. </dl>
  508. </div>
  509. </div>
  510. </body>
  511. </html>