简体   繁体   English

使用 ColorPicker 将字体颜色设置为 div

[英]Set font color to divs with ColorPicker

So, I used this jscolor to pick my color: http://jscolor.com/ Works just fine for php purposes, but I want my divs with class "color-font" to respond to whatever color I pick.所以,我使用这个 jscolor 来选择我的颜色: http ://jscolor.com/ 可以很好地用于 php 目的,但我希望我的 div 类“color-font”能够响应我选择的任何颜色。 Meaning, I want divs with class "color-font" to change their font-color as I pick color from that palette.意思是,当我从该调色板中选择颜色时,我希望具有“color-font”类的 div 更改它们的字体颜色。

I am using ColorPicker to make divs change their font, and it does not work.我正在使用 ColorPicker 使 div 更改其字体,但它不起作用。 Link to color picker: http://www.eyecon.ro/colorpicker/颜色选择器链接: http : //www.eyecon.ro/colorpicker/

Here is what I have as far as code:这是我所拥有的代码:

This is input palette:这是输入调色板:

<input type="text" size="1" name="color_font" id="color_font" value="<?php echo $t_content["color_font"]["content"]; ?>" style="font-size: 0px;  background-color: <?php echo $t_content["color_font"]["content"]; ?>; color: <?php echo $t_content["color_font"]["content"]; ?>;" class="color {hash:true}" /> 

Here is the javascript code Where I am trying to pick the color from input with ID = "color_font" and set it in divs with class = "color-font"这是javascript代码,我试图从ID =“color_font”的输入中选择颜色并将其设置在class =“color-font”的div中

$('#color_font').ColorPicker({
    //color: $(this).val(),

    onBeforeShow: function() {
        $('#color_font').ColorPickerSetColor($('#color_font').val());
    },
    onChange: function(hsb, hex, rgb) {
        var element_p = $('#color_font');
        var old_color_accent = $('#color_font').css('color');

        $('.color-font').each(function() { $(this).css('color', '#' + hex); });


        element_p.css('background-color', '#' + hex);
        element_p.css('color', '#' + hex);
        element_p.val('#' + hex);
    },
    onSubmit: function(hsb, hex, rgb, el) {
        $('#color_font').ColorPickerHide();
    }
});

I don't understand why it does not work.我不明白为什么它不起作用。

You can register the chosen color in the database, in your system you seek the result of the chosen color and shows this result in style sheet that will be in php format.您可以在数据库中注册所选颜色,在您的系统中查找所选颜色的结果,并将该结果显示在 php 格式的样式表中。 You can not get the style sheet in another file, you can have a php file with the stylesheet and include this file in your pages.您无法在另一个文件中获取样式表,您可以使用带有样式表的 php 文件并将此文件包含在您的页面中。 You need to create a php file with the style sheet which is expected to be the class of the div that will have the color you choose.您需要使用样式表创建一个 php 文件,该样式表应该是具有您选择的颜色的 div 的类。

example your_page.php :例如 your_page.php :

       <style type="text/css">
        .my_color{
            color: <?php echo $mycolor; ?>;
            background: <?php echo $mybackground; ?>;
        }
        </style>


<div class="my_color">
This is my color!
</div>

    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM