简体   繁体   English

当某个元素花费太长时间加载时激活div

[英]Activating a div when a certain element takes too long to load

How can I make a hidden div activate (or unhide) If a certain Div is taking longer than 30 seconds to completely load all elements within it? 如果某个Div耗时超过30秒才能完全加载其中的所有元素,如何使隐藏的div激活(或取消隐藏)?

I can't figure out a code. 我不知道代码。

Assuming your HTML looks something like this 假设您的HTML看起来像这样

<body>
    <img src="...">
</body>

you could do something like this: 您可以执行以下操作:

<body>
    <script type="text/javascript">slowTimer = setTimeout(function() { $("#slowLoadingDiv").show(); }, 30000)</script>;
    <img src="...">
    <script type= "text/javascript">clearTimeout(slowTimer);</script>
</body>

Basically, before your "slow loading" code, you start a timer, and when it fires you do something. 基本上,在“缓慢加载”代码之前,您需要启动一个计时器,并在其触发时执行某些操作。 After the DOM loads, you cancel said timer. DOM加载后,您取消所述计时器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM