我想要闻一下链接的颜色,如果我将鼠标悬停在它上面,而不是真正地悬停在它上面,它会变成什么颜色。我想这样做的原因是,我知道如何将它改回使用animate,因为颜色可以通过动态应用的各种皮肤来设置。我能用javascript或jquery来做这件事吗(或者有没有其他方法可以做到)?
编辑:我已经实现了这个使用CSS的过渡,但我需要的javascript的IE9及以下
发布于 2012-12-01 03:41:37
您可以从样式表中获取值:http://jsfiddle.net/wt3qQ/
// code I found here: http://catcode.com/dominfo/getstyle2.html
function getStyleBySelector( selector )
{
var sheetList = document.styleSheets;
var ruleList;
var i, j;
/* look through stylesheets in reverse order that
they appear in the document */
for (i=sheetList.length-1; i >= 0; i--)
{
ruleList = sheetList[i].cssRules;
for (j=0; j<ruleList.length; j++)
{
if (ruleList[j].type == CSSRule.STYLE_RULE &&
ruleList[j].selectorText == selector)
{
return ruleList[j].style;
}
}
}
return null;
}
console.log(getStyleBySelector('a:hover').color);
console.log(getStyleBySelector('#link:hover').color);发布于 2012-12-01 02:58:37
如果你想要为颜色设置动画效果,那么(对于现代浏览器)你可以启用颜色的过渡,这样它就会自动动画到:hover上的任何颜色
要应用代码,您可以这样做
$('element').css({
'-webkit-transition':'color 0.5s',
'-moz-transition':'color 0.5s',
'-o-transition':'color 0.5s',
'transition':'color 0.5s',
});https://stackoverflow.com/questions/13651337
复制相似问题