您可以改用悬停。
$('img').hover( function (){
console.log('hovered in');
}, function (){
console.log('hovered out');
}
不要忘记在制作动画之前放置stop() 。
所以尝试你的代码看起来像这样。
$('img').hover( function (){
console.log('hovered in');
$('img').stop().animate({'opacity': '1'}, 1500);
}, function (){
console.log('hovered out');
$('img').stop().animate({'opacity': '0.5'}, 1500);
}
另一种解决方案,如果您想做 CSS 方法,请这样做。
$('img').hover( function (){
$('img').addClass('hovered');
}, function (){
$('img').removeClass('hovered');
}
在你的 CSS 上。
img {
opacity: 0;
}
.hovered {
opacity: 1;
}
您是否也考虑过使用 CSS Webkit 进行褪色?