我不知道为什么,但是悬停“出”函数中的 animate() 似乎是从0
值开始的,而不是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 bug。无论如何,这将起作用:
$('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'});
}});
});