当前位置:   article > 正文

JS特效第155弹:js拾色器插件colorpicker.js

拾色器插件

          原生JS实现的拾色器,先来看看效果:

        一部分关键的代码如下:

  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>colorpicker</title>
  8. <script src="./colorpicker.js"></script>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. .picker {
  15. width: 300px;
  16. height: 20px;
  17. cursor: pointer;
  18. position: absolute;
  19. left: 40px;
  20. top: 40px;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="abc">
  26. <h3>点击下方选择颜色</h3>
  27. <div class="picker" id="color-picker"></div>
  28. </div>
  29. </body>
  30. <script>
  31. var obj = document.getElementById("picker");
  32. var a = Colorpicker.create({
  33. el: "color-picker",
  34. color: "#000fff",
  35. change: function (elem, hex) {
  36. elem.style.backgroundColor = hex;
  37. }
  38. })
  39. </script>
  40. </html>

        全部代码:js拾色器插件colorpicker.js

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号