(超好用)html 颜色选择器的用法


本文摘自PHP中文网,作者不言,侵删。

本篇文章给大家带来的内容是关于(超好用)html 颜色选择器的用法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

@*以下 是测试html 颜色选择器的*@

@*<a href="#" mce_href="#"

onclick="initColorPicker('demo'); return false" id="demo"

style="position:absolute;left:200px">颜色选择</a>*@

<!-- Color Picker -->

@*<script type="text/JavaScript">

        var colorPicker = function (idStr) {

 

            this.colorPool = ["#000000", "#993300", "#333300",

"#003300", "#003366", "#000080", "#333399", "#333333", "#800000",

"#FF6600", "#808000", "#008000", "#008080", "#0000FF", "#666699",

"#808080", "#FF0000", "#FF9900", "#99CC00", "#339966", "#33CCCC",

"#3366FF", "#800080", "#999999", "#FF00FF", "#FFCC00", "#FFFF00",

"#00FF00", "#00FFFF", "#00CCFF", "#993366", "#CCCCCC", "#FF99CC",

"#FFCC99", "#FFFF99", "#CCFFCC", "#CCFFFF", "#99CCFF", "#CC99FF",

"#FFFFFF"];

            this.initialize(idStr);

        }

        colorPicker.prototype = {

            initialize: function (idStr) {

                var count = 0;

                var html = '';

                var self = this;

 

                html += '<table cellspacing="5" cellpadding="0"

border="2" bordercolor="#000000"

style="cursor:pointer;background:#ECE9D8"

mce_style="cursor:pointer;background:#ECE9D8" >';

                

 // html+= '<tr><td align="center" colspan="8" width="160"

height="20" id="currentColor"

bgcolor="#ffffff">当前颜色</td></tr>';

                for (i = 0; i < 5; i++) {

                    html += "<tr>";

                    for (j = 0; j < 8; j++) {

 

                        html += '<td align="center" width="20"

height="20" style="background:' + this.colorPool[count] + '"

mce_style="background:' + this.colorPool[count] + '"

unselectable="on"> </td>';

                        count++;

                    }

                    html += "</tr>";

                }

                html += '</table>';

                this.trigger = document.getElementById(idStr);

                this.p = document.createElement('p');

                this.p.innerHTML = html;

                var tds = this.p.getElementsByTagName('td');

                for (var i = 0, l = tds.length; i &lt; l; i++) {

                    tds[i].onclick = function () {

                        self.setColor(this.style.backgroundColor, idStr);

                    }

                }

                this.p.id = 'myColorPicker';

                this.trigger.parentNode.appendChild(this.p);

                this.p.style.position = 'absolute';

                this.p.style.left = this.trigger.offsetLeft + 'px'

                this.p.style.top = (this.trigger.clientHeight + this.trigger.offsetTop) + 'px';

                //this.hide();

                this.trigger.onclick = function () {

                    if (self.p.style.display == 'none') {

                        self.show();

                        return false;

                    } else {

                        self.hide();

                        return false;

                    }

                }

            },

            setColor: function (c, idStr) {

                this.hide();

                // document.getElementById(idStr).style.backgroundColor = c //proEditor.setColor(c); //自己定义函数决定setColor的功能

                document.getElementById(idStr).style.color = c

                //var rgb2Hex = colorRGB2Hex(c);

                //alert(rgb2Hex);

            },

            hide: function () {

                this.p.style.display = 'none'

            },

            show: function () {

                this.p.style.display = 'block'

            }

        }

        function initColorPicker(str) {

            picker = new colorPicker(str);

        }

        function colorRGB2Hex(color) {

            var rgb = color.split(',');

            var r = parseInt(rgb[0].split('(')[1]);

            var g = parseInt(rgb[1]);

            var b = parseInt(rgb[2].split(')')[0]);

var hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);

            return hex;

        }

    </script>*@

相关推荐:

HTML颜色选择器实现代码_javascript技巧

5款Javascript颜色选择器_javascript技巧

以上就是(超好用)html 颜色选择器的用法的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

Html元素有哪些自带样式,如何去除

Html <br>与<p>标签区别

怎么在Html增加css

Html里的事件怎么使用

Html怎么设置编码

Html5播放视频的标签是什么?如何在web页面播放视频呢?(内附实例)

jsp与Html之间有什么区别

Html 属性

div标签:水平居中和垂直居中的实现(附代码)

Html边框线怎么设置

更多相关阅读请进入《Html》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...