百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>html5教程> (超好用)html 色彩选中器的用途
分享文章到:

(超好用)html 色彩选中器的用途

发布时间:09/01 来源:未知 浏览: 关键词:
本篇文章给大家带来的内容是关于(超好用)html 色彩选中器的用途,有必然的参照 价值,有需要的伴侣可以参照 一下,但愿对你有所帮忙。

@*以下 是测试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 < 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 色彩选中器的用途的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

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

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

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

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有152人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板