我应该使用window.load还是document.ready jquery [英] Should I use window.load or document.ready jquery

查看:202
本文介绍了我应该使用window.load还是document.ready jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我看到你可以使用

$('document').ready(function() {
//Do Code
});

$('window').load(function() {
//Do Code
});

jQuery的

for jQuery.

然而,他们是对我来说似乎一样!但显然不是。

However, they seem the same to me! But clearly aren't.

所以我的问题是:我应该使用哪一个基于动画和异步的网站?还有哪一个通常更好用?

So my question is: Which one should I use for a website sort of based on animation and async? And also which one of the two is generally better to use?

谢谢。

推荐答案

$('document')。ready 在DOM准备就绪时运行代码,但在页面本身加载时则不运行,即该网站尚未绘制,并且尚未加载图片等内容。

$('document').ready runs the code when the DOM is ready, but not when the page itself has loaded, that is, the site has not been painted and content like images have not been loaded.

$(window).load 在绘制页面并加载所有内容时运行代码。当您需要获取图像的大小时,这可能会有所帮助。如果图像没有样式或宽度/高度,除非使用 $(窗口).load ,否则无法获得其大小。

$(window).load runs the code when the page has been painted and all content has been loaded. This can be helpful when you need to get the size of an image. If the image has no style or width/height, you can't get its size unless you use $(window).load.

这篇关于我应该使用window.load还是document.ready jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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