javascript - 有没有办法可以为 AJAX 加载的图像添加悬停效果?

标签 javascript jquery

是否可以向 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 EventsDelegates是要走的路:

$('.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/

相关文章:

javascript - 如何处理 Node.js 中的文件上传中断

javascript - 如何在用于在网页中播放 .swf 的 Flash 播放器中使用控件?

javascript - 如何从外部触发的自定义插件内部获取事件而不将其作为参数传递?

javascript - CSS : Overlaying divs on top of each other using flexbox syntax(vw, vh)?

javascript - 如何弹出相对于div的内容

javascript - 在nodejs中发送消息太快 'net'

jquery - 从 jQuery 对象中删除 DOM 元素

jquery - 如何使用jquery将数据传递到node.js后端

javascript - 我想在单击该 tr 中的按钮时找到最接近的 td

javascript - PHP 使用 AJAX 和 DataTables 发布数据