渐进增强和初始显示状态

发布于 2024-09-14 06:31:04 字数 484 浏览 10 评论 0原文

我有一个具体的例子,但我也在寻找一般的答案。如果启用了 JavaScript,我希望最初隐藏一些页面元素。

示例:

  1. 表单的一部分,用于
  2. 切换选择框“跳转表单”的提交按钮

我试图在页面加载后隐藏元素时避免“内容闪烁”。


解决方案

为了后代,我将完整的解决方案放在这里。

部分中调用的 JavaScript 文件:document.documentElement.className = 'js';

允许最初隐藏或显示元素的样式:

.js .inithide {
    display: none;
}
.initshow {
    display: none;
}
.js .initshow {
    display: block;
}

I have a specific example, but I'm looking for the answer in general as well. I have page elements that I want to have initially hidden if JavaScript is enabled.

Examples:

  1. A section of a form that toggles
  2. A submit button for a select box 'jump form'

I am trying to avoid the 'content flash' when the elements are hidden after page load.


SOLUTION

I am putting the full solution here for posterity's sake.

JavaScript file called in <head> section: document.documentElement.className = 'js';

Styles that allow for initially hidden or shown elements:

.js .inithide {
    display: none;
}
.initshow {
    display: none;
}
.js .initshow {
    display: block;
}

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

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

发布评论

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

评论(1

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