Progressive Enhancement and Initial Display State

回眸只為那壹抹淺笑 提交于 2020-01-05 05:33:08

问题


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;
}

回答1:


Check this solution out. It has worked for me in the past:

http://www.learningjquery.com/2008/10/1-way-to-avoid-the-flash-of-unstyled-content



来源:https://stackoverflow.com/questions/3461152/progressive-enhancement-and-initial-display-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!