JS预加载器页面加载前内容泄露问题求助
页面预加载器内容泄露问题求助
我尝试从模板中实现一个JS预加载器,但始终无法解决页面加载前部分内容泄露的问题。尽管逻辑看似合理,但无论如何尝试,.home-content__main类下的部分文本元素仍会在页面加载前泄露,该主题演示站在这方面运行正常。
相关JS代码
$WIN = $(window); // Add the User Agent to the <html> // will be used for IE10 detection (Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)) var doc = document.documentElement; doc.setAttribute('data-useragent', navigator.userAgent); var clPreloader = function() { $("html").addClass('cl-preload'); $WIN.on('load', function() { //force page scroll position to top at page refresh $("html").animate({ scrollTop: 0 }, 'normal'); // will first fade out the loading animation $("#loader").fadeOut("slow", function() { // will fade out the whole DIV that covers the website. $("#preloader").delay(300).fadeOut("slow"); }); // for hero content animations $("html").removeClass('cl-preload'); $("html").addClass('cl-loaded'); }); }; [...] (function ssInit() { clPreloader(); })(); [...] })(jQuery);
对应CSS样式
html.cl-preload .home-content__main { opacity: 0; display: none !important; } html.cl-loaded .home-content__main { animation-duration: 2s; -webkit-animation-name: fadeIn; animation-name: fadeIn; } html.no-csstransitions .home-content__main { opacity: 1; }
已尝试的解决方法
- 通过CSS设置
.home-content__main元素为visibility: hidden !important、display: none !important等,均无效; - 将
$WIN.on('load', function())替换为$(window).on('load', function())和$('document').ready(function()),无效; - 曾怀疑是Rocket Loader干扰,但将脚本及依赖加入白名单后问题依旧。
我已无计可施,请问遗漏了什么?感谢各位的建议和意见!
内容的提问来源于stack exchange,提问作者user22082637
相关产品推荐
相关产品推荐

