【发布时间】:2011-01-13 21:24:01
【问题描述】:
这里的回调函数不起作用。我认为我错误地使用了 startColor 变量。
注意:这需要 jQuery UI。
$("a").hover(function() {
var startColor = $(this).css("color");
$(this).stop().animate({ color: "#54a888"}, 350);
},function() {
$(this).stop().animate({ color: " + startColor + "}, 350);
});
谢谢各位。我实际上是在尝试重构这段代码:
$("nav ul li a, aside ul li a").hover(function() {
$(this).stop().animate({ color: "#54a888"}, 350); //End color
},function() {
$(this).stop().animate({ color: "#5944b2"}, 350); //Start color
});
$("h5#logo a, button").hover(function() {
$(this).stop().animate({ backgroundColor: "#54a888"}, 350);
},function() {
$(this).stop().animate({ backgroundColor: "#000000"}, 350);
});
$("h3 a").hover(function() {
$(this).stop().animate({ color: "#54a888"}, 350);
},function() {
$(this).stop().animate({ color: "#000000"}, 350);
});
我有不同的起始颜色和不同的属性要制作动画。似乎有比重复相同代码 3 次更好的解决方案。
【问题讨论】:
-
请原谅我的错误格式
-
我不是 jQuery 专家,但您没有在刚刚发布的内容中使用
startColor变量 - 您只有确切的字符串" + startColor +"
标签: jquery variables colortransform