我不知道为什么,在悬停"out"函数中的animate()似乎从0
值开始,而不是应该由悬停"in"函数设置的16
值:
$.fx.step.textShadowBlur = function(fx) {
$(fx.elem).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px #000'});
};
$('a').hover(function(){
$(this).stop().animate({textShadowBlur:16}, {duration: 400});
}, function(){
$(this).stop().animate({textShadowBlur:0}, {duration: 900});
});
鼠标移出时,我突然看到文本阴影发生了变化,没有动画效果。
我做错了什么?
jsfiddle
好的,我已经解决了。似乎是jQuery在定义步骤函数时出现了错误或其他问题。无论如何,下面的代码可以正常工作:
$('a').hover(function(){
$(this).stop().animate({nothing:16}, {duration: 400, step: function(now, fx){
$(this).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px #000'});
}});
}, function(){
$(this).stop().animate({nothing:0}, {duration: 900, step: function(now, fx){
$(this).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px #000'});
}});
});