虹膜颜色选择器

时间:2013-09-10 23:06:59

标签: jquery css colors picker

目标是改变链接的颜色,但改变悬停状态的颜色。

这将是完美的:
jQuery(“body”)。css(“background-color”,ui.color.toString());

但是如果你想改变悬停的颜色它将不起作用:
jQuery(“a:hover”)。css(“color”,ui.color.toString());

完整的脚本是:

$('#wide-load').iris({
        width: 170,
        hide: false,
        palettes: ['#125', '#459', '#78b', '#ab0', '#de3', '#f0f'],
        change: function(event, ui) {           
                jQuery("body").css( "background-color", ui.color.toString());
                jQuery("a:hover").css( "color", ui.color.toString());
        }
});


在线脚本: http://automattic.github.io/Iris/

1 个答案:

答案 0 :(得分:0)

我知道自从你问这个问题已经好几个月了,但是我在完全相同的情况下挣扎,最后找到了解决方案。

对我来说有用的是使用jQuery向<div>添加空body,然后在每次更改颜色时在其中打印<style>标记,如下所示:

function changeHoverColor(){
    /* 
    check if your '#custom-css' div exists on page
    if not then create it and append it to the body
    */
    if( $('#custom-css').length < 1 ){
        var $cssDiv = $('<div id="custom-css">');
        $cssDiv.appendTo('body');
    }

    var myColor = '#ff7700'; //change this to your color

    /* change the below css to fit your needs */
    var myStyle = '<style>a:hover{color:'+myColor+';}</style>';

    /* 
    finally print it inside your div.
    Now, every time you pick a color, your new css will be generated and will
    overwrite the previous one inside the '#custom-css' div
    */
    $('#custom-css').html(myStyle);
}

希望它有所帮助。干杯