加载所有图像后加载页面

发布于 2024-11-17 23:54:38 字数 177 浏览 10 评论 0原文

我的背景图像相当大。当我的页面加载时,HTML 在背景图像加载到页面之前呈现。我希望背景图像首先加载到页面上,然后是 HTML。现在看起来很奇怪,因为没有背景图像,文本会被推高,而当加载背景图像时,所有文本都会被推到常规位置(看起来不太专业)。

无论如何,javascript 中是否可以实现此目的?

谢谢!

My background image is decently large. When my page loads, the HTML is rendered before the background image is loaded onto the page. I would like for the background image to be the first thing to be loaded on the page and then the HTML. Right now it looks weird because without the background image, the text gets pushed up and when the background image is loaded, it all gets pushed to its regular position (not too professional-looking).

Is there anyway in javascript to accomplish this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尸血腥色 2024-11-24 23:54:38

我认为预加载图像并不能解决您的问题,因为您希望在向用户显示 HTML 文档之前加载图像。

我没有确切的解决方案,但我所做的是在页面加载时向用户显示加载图像,然后在正文和图像完全加载时隐藏该加载图像。做到这一点

    <body onLoad="document.getElementById('mydiv').setAttribute('style','display:none');">
    <div id=mydiv style="position:absolute;top:0px;left:0px;width:100%;height:100%>
<center> <img src="loading.png>
</center>
</div>


    <!-- Other HTML content here -->

    </body>

这只是一个粗略的代码,希望这有帮助

I think pre-loading an image is not a solution to you problem since you want the Images to load Before the HTML document is displayed to the user.

i dont have an exact solution but what i did was show a LOADING image to the user while the page loads up and then hide that loading image when the body and images are completely loaded. to do this

    <body onLoad="document.getElementById('mydiv').setAttribute('style','display:none');">
    <div id=mydiv style="position:absolute;top:0px;left:0px;width:100%;height:100%>
<center> <img src="loading.png>
</center>
</div>


    <!-- Other HTML content here -->

    </body>

This is just a rough code, hope this helps

云朵有点甜 2024-11-24 23:54:38

您可以编写 javascript,在加载所有内容后将页面的其余部分添加到 DOM。
这是使用 jQuery 可以做的最简单的事情之一。

但是,我不明白这一点。作为用户,我不希望你对我这样做。

You can write javascript that adds the rest of the page to the DOM once everything is loaded.
It's one of the easiest things you can do with jQuery.

However, I don't see the point. As a user I don't want you to do that to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文