检测对象是否已加载 [Javascript]
我想知道,有没有办法检测是否加载了某个图像/div? 例如,当我加载两个沉重的图像并在图像稍后占据的两个位置显示加载标志时,有没有办法在加载时显示第一个图像,同时仍在加载第二个图像?
I was wondering, is there a way to detect if a certain image / div is loaded?
For example when i am loading two heavy images and showing a loading sign at the two places the images will later occupy, is there a way to already display the first image when it's loaded while still loading the second one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当图像加载完成时,将调用上述函数内的代码。
Code inside the above function will be called when the image is finished loading.
如果您使用
new Image
来预加载图像,那么您可以执行以下操作以在加载后收到通知记住设置
src
afteronload
。If you are using
new Image
to preload images, then you can do the following to be notified of then it is loadedRemember to set the
src
after theonload
.如果图像加载完成,其
.complete
属性将切换为 true。if an image is done loading, its
.complete
property switches to true.