简体   繁体   English

加载页面后淡入内容

[英]Fade content in after page loads

What's the best way to do this, and how do you make it browser-proof? 最好的方法是什么,如何使它与浏览器兼容? For example, this post establishes that best practice is to cover your content with an opaque div and fade that out after load. 例如, 本文确定最佳实践是使用不透明的div覆盖您的内容,并在加载后将其淡出。 But what if the client has javascript disabled? 但是,如果客户端禁用了javascript怎么办? PHP detection of JS isn't reliable, and if one were to go with the opaque div method you would never see the content in a JS-disabled browser. PHP对JS的检测是不可靠的,如果使用不透明的div方法,您将永远不会在禁用JS的浏览器中看到内容。

Ideas? 想法?

You can set default of the overlay element to display: none in css and use document.write to insert a style tag in head (after main css) that sets it to display:block. 您可以将overlay元素的默认值设置为display: none在css中display: none ,并使用document.write在head中(在主css之后)插入样式标签,将其设置为display:block。 If js disabled will never be seen since the write will be ignored. 如果禁用了js,将不会被看到,因为write将被忽略。

Another way is to use script in your head to add a class to html tag such as js_enabled , make css rule like 另一种方法是使用脑海中的脚本将类添加到js_enabled这样的js_enabled ,使css规则如下

.overlay { display:none}
.js_enabled .overlay { display:block}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM