实时 HTML5 灰度

发布于 2024-12-29 17:58:39 字数 546 浏览 1 评论 0原文

我需要将此脚本用于网站画廊: http://webdesignerwall.com/tutorials /html5-grayscale-image-hover/

这对于已加载的图像非常有用:

   $(window).load(function(){
                $('.item img').each(function(){
        this.src = grayscale(this.src);
        });
    });
function grayscale(src){ //blabla };

问题是我使用 ajax 加载下一个图像,并且效果不会应用于新的 ajax 元素。

谢谢你!

如果我成功加载函数,效果将覆盖现有的灰色图像!

I need to use this script for a website gallery: http://webdesignerwall.com/tutorials/html5-grayscale-image-hover/

This works great for images already loaded:

   $(window).load(function(){
                $('.item img').each(function(){
        this.src = grayscale(this.src);
        });
    });
function grayscale(src){ //blabla };

The problem is that I load next images with ajax, and the effect is not applied to new ajax elements.

Thank you!

If I load my function on success, the effect will overwrite the existent grayed images!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那一片橙海, 2025-01-05 17:58:39

在 AJAX 成功回调时调用该方法:

function foo(){
    $('.item img').each(function(){
    this.src = grayscale(this.src);
    });
}

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: foo,
  dataType: dataType
});

call that method on success callback of the AJAX:

function foo(){
    $('.item img').each(function(){
    this.src = grayscale(this.src);
    });
}

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: foo,
  dataType: dataType
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文