使用 jQuery Ajax 请求交换图像 src

发布于 2024-07-27 01:10:18 字数 234 浏览 2 评论 0原文

我有一个 标记,并设置了默认的 src 。 我想让 jQuery 发出 ajax 请求来获取另一个图像,当这个新图像完全加载时,设置 标记的 src,这样就不会闪烁。 我不想做任何预加载器,比如 new Image().src="foo" 等。我真的很希望在 ajax 请求上加载 iamges。 有任何想法吗?

I have an <img src="..." /> tag with a default src set. I'd like to have jQuery make an ajax request to get another image and when this new image is fully loaded, set the src of the <img ... /> tag so there's no flicker. I'd prefer not to do any of the preloaders like new Image().src="foo" etc. I'd really like the iamges to load on an ajax request. Any ideas?

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

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

发布评论

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

评论(1

风吹雨成花 2024-08-03 01:10:18

您无法将图像的“一部分”加载到网页上,因此无法增量加载它。

可以通过使用指向图像的 CSS 类或使用 Javascript 的 Image 对象来加载图像。

由于 CSS 无法通知页面图像是否完全加载,因此 new Images().src = "foo" 的方法是它能做的最好的方法。

向其附加一个事件并“装饰”它以通过 FX 效果减少闪烁:淡入,...

You cannot load "a part" of a image onto the webpage so you cannot load it incrementally.

The image can be loaded by using a CSS class point to an image or using Image object of Javascript.

Since CSS cannot notify the page whether the image fully load so the approach new Images().src = "foo" is the best it can do.

Attach an event to it and "decorate" it to reduce flicker with FX effect: fade in, ....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文