是否可以向 AJAX 加载的内容/图像添加悬停效果(动画)?目前我正在使用此代码来执行此操作,但它仅适用于不使用 AJAX 加载的图像。
$(".box img").each(function() {
$(this).hover(function() {
$(this).stop().animate({ opacity: 1.0 }, 500);
},
function() {
$(this).stop().animate({ opacity: 0.3 }, 500);
});
});
最佳答案
Live Events或Delegates是要走的路:
$('.box').delegate('img', {
mouseenter: function() {
$(this).stop().animate({ opacity: 1.0 }, 500);
},
mouseleave: function() {
$(this).stop().animate({ opacity: 0.3 }, 500);
}
});
顺便说一句,在您的原始代码中,无需使用 each
- 您可以使用 $('.box img').hover(...)
关于javascript - 有没有办法可以为 AJAX 加载的图像添加悬停效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6408802/