简体   繁体   English

推迟执行HTML页脚,直到加载Javascript

[英]Defer execution of html footer until Javascript loads

I am adapting a Wordpress theme for a client. 我正在为客户调整Wordpress主题。

Within the theme, there is a portfolio feature which loads using javascript. 在主题内,有一个使用javascript加载的投资组合功能。 Unfortunately, execution of the javascript is fairly slow, so the result is the footer flashing in the middle of the screen before being pushed to the bottom. 不幸的是,javascript的执行速度相当慢,因此结果是页脚在被推到底部之前在屏幕中间闪烁。 This is pretty unsightly - You can see it here: http://bit.ly/1nCH0Br 这非常难看-您可以在这里看到它: http : //bit.ly/1nCH0Br

Is there a way to defer the execution of the footer until the javascript has finished executing (or any better way of solving this unpleasant problem?) 有没有一种方法可以将页脚的执行推迟到javascript完成执行为止(或解决此不愉快问题的更好方法?)

You could make the footer part of the portfolio, so that it doesn't load until the portfolio loads, but that will still leave you with the problem that the page looks blank for the first few seconds of a visit. 您可以将页脚作为投资组合的一部分,以便直到投资组合加载后才加载它,但这仍然会给您带来一个问题,即在访问的前几秒钟页面看上去空白。

A better solution would be to adapt the theme so that it includes a div with a fixed height that displays a loading image and some text like "Loading...". 更好的解决方案是调整主题,使其包括具有固定高度的div ,以显示加载图像和诸如“ Loading ...”之类的文本。 You can adapt the carousel to replace this div. 您可以修改轮播以替换此div。 That way you can push the footer down to the bottom of the page, AND give the user some feedback that there's more content loading in the background. 这样,您可以将页脚向下推至页面底部,并向用户提供一些有关后台加载更多内容的反馈。

Initialize your footer with css: 用CSS初始化页脚:

position: absolute;
left: -10000px;
opacity: 0;

and set the correct values when the page has loaded. 并在页面加载后设置正确的值。 You can do this with having 2 classes, one for preloads and another for after load. 您可以使用2个类来实现此目的,一个类用于预加载,另一个用于后加载。

The reason of not just hidding the footer with css is that your js can still work with width and height values 不只是用CSS隐藏页脚的原因是您的JS仍然可以使用width和height值

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

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