添加加载动画,直到特定的javascript完成加载为止 [英] add a loading animation until a specific javascript finish loading

查看:78
本文介绍了添加加载动画,直到特定的javascript完成加载为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部JavaScript src,我想添加一个加载动画,直到加载完成:

I have an external JavaScript src which I want to add a loading animation until it's finish loading:

<script src="https://xxxx.domain.com/xxx.js" type="text/javascript"></script>

我当前正在使用jQuery(窗口).load,但是它一直等到所有页面完全加载后,我只想等待那个特定的代码:

I'm currently using jQuery (window).load, but its waiting until all page is fully loaded, I want to wait only for that specific code:

<script>$(window).load(function(){$(".loadingif").hide();});</script>

更新: 正如您所建议的,这是我的代码,它不起作用,我在做什么错---

Update: This is my code as you have suggested, it's is not working, what I'm doing wrong---

some text.....
<span class="loading-gif"></span>
<script src="https://xxxx.domain.com/xxx.js" type="text/javascript"></script>
<script>hideLoading();</script>
some text.....
<script>function hideLoading(){$(".loading-gif").hide();}</script>

推荐答案

希望这可行:

<script src="https://xxxx.domain.com/xxx.js" type="text/javascript"></script>
<script type="text/javascript">
    hideLoadingThingy();
</script>

第二个脚本应在第一个脚本完成加载后运行.这是因为它包含在第一个之后,因此第一个被首先加载.

The second script should run after the first one finishes loading. This is because it is included after the first one, so the first one is loaded first.

除非xxx.js中的方法被异步调用,否则浏览器一次只能执行一个任务.在此处

Unless the methods in xxx.js are called asynchronously, your browser will only execute one task at a time. Read more about that here

更新:

使用此:

some text 2.....
<span class="loading-gif"></span>
<script src="https://xxxx.domain.com/xxx.js" type="text/javascript"></script>
<script type="text/javascript">$(".loading-gif").hide();</script>
some text 2.....

这篇关于添加加载动画,直到特定的javascript完成加载为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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