简体   繁体   English

动态内容预加载器

[英]Preloader for dynamic content

I have dynamic page which takes about 8 seconds to load searched data. 我有动态页面,大约需要8秒钟来加载搜索到的数据。

Problem is, all browsers remain on old page for those 8 secs & show dynamic page only after it 问题是,所有浏览器会在旧页面上停留8秒钟,并且仅在它之后显示动态页面

loads completely. 完全加载。

What I want is preloder image to be shown to the customers until second page gets load. 我要的是在客户加载第二页之前显示给客户的preloder图片

How can I achieve this? 我该如何实现?

Thanks 谢谢

I assume you are loading the second page through AJAX. 我假设您正在通过AJAX加载第二页。 If so, you'll only be able to display the results after the asynchronous call returns. 如果是这样,您将只能在异步调用返回显示结果。

However, nothing prevents you from making changes to the page before sending off the AJAX request. 但是,没有什么可以阻止您发送AJAX请求之前对页面进行更改。 The basic structure will be: 基本结构将是:

var preload = $('<div></div>').text('I am preloading!').insertAfter('somewhere');
$.get(..., function() {
    preload.remove();
    // insert your real content, received from this AJAX request
});
$('<div id="busy">Loading...</div>')
        .ajaxStart(function() {$(this).show();})
        .ajaxStop(function() {$(this).hide();})
        .appendTo('body');

That's all! 就这样!

You may want to add some style to #busy tag, but this you can do with CSS. 您可能想为#busy标签添加一些样式,但是您可以使用CSS进行此操作。

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

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