这里的回调函数不起作用。我想我错误地使用了 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 次更好的解决方案。