2013-09-10 76 views
0

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

这将工作完美:
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/

回答

0

我知道这已经好几个月了,因为你问这个,但我同样的事情努力,终于找到一个办法。

我什么工作是一个空<div>body使用jQuery,然后打印里面一个<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); 
} 

希望它能帮助。干杯

+0

谢谢!它帮助了很多.. –