完全呈现页面后运行javascript [英] Running javascript after page is fully rendered

查看:121
本文介绍了完全呈现页面后运行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建语法高亮显示脚本。我尝试在一万行代码上使用我的脚本,所有我看到的是加载时的空白页面。脚本完成任务后,一切都会显示出来。顺便说一句,我在jQuery的ready函数中调用了我的脚本。

I am trying to create a syntax highlighter script. I tried using my script on a code with 10 thousand lines and all I see is a blank page while it is loading. Everything will just show up after the script has finished it's task. By the way, I called my script inside the ready function of jQuery.

$(myFunction);

脚本应在页面完全呈现后执行,即使用户可以实际浏览页面该脚本尚未完成。 javascript将在后台运行,因为它会逐一突出显示代码,同时不会干扰页面的重复性。提前致谢。

The script should execute after the page is fully rendered and the user can actually navigate through the page even if the script is not yet finished. The javascript will run in the background as it highlights the code one by one while not interfering the reponsiveness of the page. Thanks in advance.

编辑:

为了更清楚,我想在一切之后执行代码被渲染而不是加载。屏幕上已经可以看到所有内容,用户可以实际看到代码在突出显示时生效。谢谢。

To make this clearer, I would like to execute the code after everything is "rendered" not "loaded". Everything should already visible in the screen and the user can actually see the code come to life as it is being highlighted. Thanks.

推荐答案

您的意思是在所有图片都已加载后?

Do you mean after all the images have been loaded?

我认为 window.onload 正是您所寻找的

window.onload = function() {
    //dom not only ready, but everything is loaded
};

编辑

Per Chris的评论,这里是jQuery方式:

Per Chris's comment, here's the jQuery way:

$(window).load(function() {
    //dom not only ready, but everything is loaded
});

这篇关于完全呈现页面后运行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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