延迟一些jQuery函数,直到所有图像完全加载 [英] Delay some jQuery function until all images are loaded completely

查看:129
本文介绍了延迟一些jQuery函数,直到所有图像完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果页面上的所有图片都加载完毕,我如何延迟一些jQuery / JavaScript函数?
实际上,我所说的jQuery函数用于设置div的偏移位置。问题是图像完全加载后页面会调整大小,因此偏移是错误的。

How do I delay some jQuery / JavaScript function until all the images on a page have finished loading? Actually, the jQuery function I'm talking about is for setting the offset position for a div. The problem is that the page resizes once the images are loaded completely, so the offset is wrong.

对于jQuery函数,请参考以下问题:在给定的页面底部固定div的问题地方

For the jQuery function refer to this question: Issues with Fixed div on bottom of page that stops at given place

推荐答案

您可以使用 onload 事件加载所有图像或外部资源后运行:

You can use the onload event which runs after all images or external resources are loaded:

$(window).load(function(){
  // your code here, all images loaded
});

您还可以使用 load 事件单个图像并在加载时运行代码:

You can also use the load event for individual images and run your code when they have loaded:

$('img.ImageClass').load(function(){
  // The image loaded....
});

这篇关于延迟一些jQuery函数,直到所有图像完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆