문제

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;
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top