嗨,我是新来的jquery。我有两个问题想不出来。我使用的是拷贝和过去的代码,因为我的最后期限很紧。
1)
当我将鼠标悬停在链接上时,一旦我将鼠标移离链接,它就不会淡出原来的颜色。
2)
如果我把鼠标快速移动到链接上,它们就会陷入一个循环,一次又一次地淡入淡出…我知道我应该可以使用stop(),但不确定这是否是我需要的。
// JavaScript Document
$(document).ready(function() {
//Grab the original BG color of the link
var originalBG = $("#nav li a").css("background-color");
//The color you want to fade too
var fadeColor = "#FFFFFF";
//Now animate on links with class = animate
$("#nav li a").hover(
function() {
$(this)
//Fade to the new color
.animate({backgroundColor:fadeColor}, 350)
//Fade back to original color
.animate({backgroundColor:originalBG}, 350)
},
function(){
}
);
});
更新:
从建议-解决了我的一些问题,但现在有些时候,如果你停留在一个链接,它不会褪色。
// JavaScript Document
$(document).ready(function() {
//Grab the original BG color of the link
var originalBG = "#351411";
//The color you want to fade too
var fadeColor = "#FFFFFF";
//Now animate on links with class = animate
$("#nav li a").hover(
function() {
//Fade to the new color
$(this).stop().animate({backgroundColor:fadeColor}, 350)
},
function(){
//Fade back to original color
$(this).stop().animate({backgroundColor:originalBG}, 350)
}
);
});