試試這個:
$(document).ready(function() {
$('label').hover(function() {
var hue = 'rgb('
+ (Math.floor(Math.random() * 256)) + ','
+ (Math.floor(Math.random() * 256)) + ','
+ (Math.floor(Math.random() * 256)) + ')';
$(this).stop().animate({ color: hue }, 500);
},function() {
$(this).stop().animate({ color: '#000' }, 500);
});
});
也看到我jsfiddle。
=== UPDATE ===
function startAnimation(o) {
var hue = 'rgb('
+ (Math.floor(Math.random() * 256)) + ','
+ (Math.floor(Math.random() * 256)) + ','
+ (Math.floor(Math.random() * 256)) + ')';
$(o.currentTarget).animate({ color: hue }, 500, function() {
startAnimation(o);
});
}
$(document).ready(function() {
$('label').hover(
startAnimation,
function() {
$(this).stop().animate({ color: '#000' }, 500);
}
);
});
看到我更新jsfiddle。
請張貼您的HTML和CSS。這裏沒有足夠的代碼來知道發生了什麼問題。 – maxedison
你需要什麼?除了身體上的東西外,沒有任何CSS。而html只是一堆輸入標籤。 – yoshi