何时才能真正触发document.ready? [英] When does document.ready actually fire?

查看:85
本文介绍了何时才能真正触发document.ready?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们考虑以下情况:

<img>标记中有一个2.5MB的图像,我的连接速度很慢,这需要花费大量时间才能下载该图像.如果我将document.ready()放在head标签中,那么它将等待图像下载,还是在下载所有HTML时启动?

There is a 2.5MB image in an <img> tag and I'm on a slow connection which takes considerable time to download that image. If I'm putting the document.ready() in the head tag, then will it wait for the image to be downloaded or it will fire when all the HTML is downloaded?

如果在下载所有HTML时触发,我该如何避免?

In case it fires when all the HTML is downloaded, how do I avoid it?

如何在传输2.5MB数据后触发.ready()函数?

How do I make the .ready() function fire after the 2.5MB data transfer?

推荐答案

$(document).ready(...)

在加载 DOM时触发(即使尚未加载多媒体)

Fire when the DOM is loaded (even if multimedia no loaded yet)

$(window).load(...)

当所有内容都加载完毕时触发(当进度指示器显示加载过程时)不见了

Fire when all the content is loaded (when the progress indicator which shows the loading process is gone)

这篇关于何时才能真正触发document.ready?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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