[英]Swap image src with jQuery Ajax request
I have an <img src="..." />
tag with a default src
set. 我有一个带有默认
src
设置的<img src="..." />
标签。 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. 我想让jQuery发出一个ajax请求来获取另一个图像,当这个新图像被完全加载时,设置
<img ... />
标签的src,这样就没有闪烁。 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. 我不想做任何像
new Image().src="foo"
等预加载器。我真的很喜欢加载ajax请求的iamges。 Any ideas? 有任何想法吗?
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. 可以使用CSS类指向图像或使用Javascript的Image对象来加载图像。
Since CSS cannot notify the page whether the image fully load so the approach new Images().src = "foo" is the best it can do. 由于CSS无法通知页面图像是否完全加载所以接近新的Images()。src =“foo”是最好的。
Attach an event to it and "decorate" it to reduce flicker with FX effect: fade in, .... 将事件附加到它并“装饰”它以减少FX效应的闪烁:淡入,....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.