Javascript jQuery fadeColor问题
嗨,我是JQuery的新手。我有两个问题无法解决。我正在使用拷贝和过去的代码,因为我的最后期限很紧 1)当我将鼠标移离链接时,它不会褪色回原始颜色 2)如果我在链接上快速移动鼠标,它们会卡在一个循环中,一次又一次地淡入淡出。。。我知道我应该能够使用stop(),但不确定这是否是我所需要的Javascript jQuery fadeColor问题,javascript,jquery,css,Javascript,Jquery,Css,嗨,我是JQuery的新手。我有两个问题无法解决。我正在使用拷贝和过去的代码,因为我的最后期限很紧 1)当我将鼠标移离链接时,它不会褪色回原始颜色 2)如果我在链接上快速移动鼠标,它们会卡在一个循环中,一次又一次地淡入淡出。。。我知道我应该能够使用stop(),但不确定这是否是我所需要的 // JavaScript Document $(document).ready(function() { //Grab the original BG color of the link
// 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)
}
);
});
试试这个:
$("#nav li a").hover(
function() {
//Fade to the new color
$(this).animate({backgroundColor:fadeColor}, 350)
},
function(){
//Fade back to original color
$(this).animate({backgroundColor:originalBG}, 350)
}
);
不起作用,因为
.css(“背景色”)
以另一种颜色格式返回,有些是这样的:“rgb(18,52,86)”。Soufiane Hassou的解决方案可能会起作用。但我不知道“动画”是否接受这种格式:“rgb(18,52,86)”。试试看;)这有点帮助。现在有些时候,如果你将鼠标悬停在某个链接上,它不会淡入或淡出。“有些时候”是指当你快速地将鼠标悬停在该链接上时,不会淡入或淡出?也许设置一个超时并在鼠标悬停时将其清除可以解决你的问题。