简体   繁体   English

如何在页面加载时预加载Javascript编写的HTML?

[英]How do I preload HTML that is written by a Javascript on page load?

So here is what I am trying to achieve. 所以这就是我想要达到的目标。 I currently have a FeedBurner script in my webpage. 我的网页上目前有一个FeedBurner脚本。 I use the <script> tags for the feed and when the page loads, the script generates the feed HTML. 我对提要使用<script>标记,并且在页面加载时,脚本会生成提要HTML。 What I'm trying to do is to have all the HTML associated with the feed to preload and then fade in. I tried putting the script in an external file and making an Ajax call but that didn't actually wait till everything was finished loading. 我想做的是让与提要相关的所有HTML都预先加载,然后淡入。我尝试将脚本放入外部文件中并进行Ajax调用,但实际上并没有等到所有内容加载完成。

I am currently using jQuery. 我目前正在使用jQuery。

Thanks. 谢谢。

Put that code in window load function instead of DOM Ready 将该代码放入window load函数中,而不是DOM Ready中

$(window).load(function() {
      // Make ajax request here and check if that helps
});

您可以在身体部位使用这样的JS函数。

<body onload="func()">

Use the ajax call on window.load like Sushanth said along with appending it with display:none and then fading it in. 像Sushanth所说的那样在window.load上使用ajax调用,并在其后面附加display:none,然后使其淡入。

$(window).load(function() {
      $content = $.get();
      $content.css('display', 'none').appendTo('#my_element').fadeIn()
});

暂无
暂无

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

相关问题 How to store data from a form written in HTML and JavaScript in a session or cookie using PHP to preload whenever the form is accessed - How to store data from a form written in HTML and JavaScript in a session or cookie using PHP to preload whenever the form is accessed 如何分析SonarQube中.php文件中编写的JavaScript代码 - How do I analyze JavaScript code written in .php file in SonarQube 我如何推迟或异步此 WordPress javascript 代码段最后加载以加快页面加载时间? - How do I defer or async this WordPress javascript snippet to load lastly for faster page load times? 在生成整个页面(由PHP动态生成)之前,如何预加载.css和.js文件 - How do I preload .css and .js files, before the whole page (dynamic by PHP) is generated 加载新的HTML页面时无法使用javascript变量 - Unable to use javascript variable when I load a new html page Javascript .replace在页面加载时被重写 - Javascript .replace being re-written on page load 如何等待我的脚本使用 PHP Simple HTML DOM Parser 加载页面? - How do I wait for my script to load the page with PHP Simple HTML DOM Parser? 如何使用Jquery或Javascript在laravel刀片模板div中加载网页? - How do I load a web page in a laravel blade template div with Jquery or Javascript? 使用javascript在html页面内加载php页面 - load a php page inside a html page with javascript 使用页面加载Javascript在HTML页面内加载PHP页面 - Load PHP page within HTML page with Javascript On Page Load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM