javascript - Next JS : 在 dom 渲染时加载屏幕
问题描述
如何显示我自己的加载程序而不是空白的白屏?例如,Tweeter 在页面加载时显示徽标,对于 Facebook、google AdSense 等也是如此。看看这个 Gif,我想要在 Next Js 中类似的东西。
我想这与 _document.js 有关。react js 有一个类似的问题(在 index.html 中渲染加载器),但我不知道如何在下一个 js 中做到这一点。
解决方案
通常这些是通过一个覆盖所有内容并默认显示的 div 来完成的,您在该 div 中放置的内容取决于您(gif、svg 等)。一旦 window.onload 被调用,只需隐藏 div,它将显示完全渲染的 dom。
这是一个基本示例(我在移动设备上,请原谅我的格式)CSS:
.loadingsScreen{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
background-color: #whatever-color;
z-index: 10; /*just make sure it's the highest on the page*/
}
JS:
window.onload = function(){
$("#loadingScreen").fadeOut(); //just make it hide the overlaying div, I used jQuery in this example but there are many ways to do this
};
推荐阅读
- node.js - 如何在 NodeJS 中使用 Array 输入重复相同的 Promise,直到它解析或 Array 结束?
- javascript - 文件上传进度条干扰控制器重定向
- r - 带有附加列的 R 频率表
- ruby-on-rails - 将 axlsx gem 与 conditional_formatting 一起使用
- pandas - 在列透视期间保留最后一个重复索引?
- c - 不同的字母程序,我不明白解决方案
- ssl - 使用 ClickOnce 部署的签名 VSTO 显示“未知发布者”
- html - 为什么 css 和图像未成功加载以及如何正确设置宽度?
- python - QThread 在线程仍在运行时被销毁
- r - 如何找出我的向量中有多少数字小于给定数字