JQTOUCH - 任何时候发生加载时,添加加载类?

发布于 2024-08-28 23:48:15 字数 157 浏览 3 评论 0原文

我正在使用 JQTOUCH,在 JQTOUCH 中,几个链接正在通过 AJAX 加载,然后滑入。问题是没有向用户提供加载指示。

我想要一种方法,在加载 ajax 调用时添加带有 AJAX 微调器的 Loading 类,并在加载完成并显示页面时删除该类。

有什么想法吗?

I'm using JQTOUCH and in JQTOUCH several of the links are being loading via AJAX and then sliding in. The problem is that there is no loading indication provided to users.

I'd like a way to add a Loading class with an AJAX spinner, when ever the an ajax call is loading, and have the class removed when the loading is done, and the page is displayed.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

窝囊感情。 2024-09-04 23:48:15

showPageByHref() 答案部分正确。

但是,

$('body').append('<div id="loadinginprogress">Loading...</div>');

您需要

$('.current').append('<div id="loadinginprogress">Loading...</div>');

Body 对于 jqtouch 来说太笼统了,需要特定于当前显示的 DIV 页面

the showPageByHref() answer is partially correct.

But, instead of

$('body').append('<div id="loadinginprogress">Loading...</div>');

You need

$('.current').append('<div id="loadinginprogress">Loading...</div>');

Body is too general for jqtouch, need to be specific to the currently displayed DIV-page

北座城市 2024-09-04 23:48:15

jqtouch js 中的 showPageByHref() 函数是一个好的开始。我将其添加到ajax调用中,这样当您单击已加载的链接等时,请稍候不会闪烁。

简而言之 - 在ajax调用之前添加加载div(exmaple中的id loadinginprogress)并删除稍后的“成功”或“错误”。 ajax 调用部分看起来像这样(缩短它):

function showPageByHref(href, options) {
...
if (href != '#'){
    $('body').append('<div id="loadinginprogress">Loading...</div>');
    $.ajax({
        url: href,
        data: settings.data,
        type: settings.method,
        success: function (data, textStatus) {
            $('#loadinginprogress').remove()
            var firstPage = insertPages(data, settings.animation);
            if (firstPage)
            {
                if (settings.method == 'GET' && jQTSettings.cacheGetRequests && settings.$referrer)
                {
                    settings.$referrer.attr('href', '#' + firstPage.attr('id'));
                }
                if (settings.callback) {
                    settings.callback(true);
                }
            }
        },
        error: function (data) {
            $('#loadinginprogress').remove()
            if (settings.$referrer) settings.$referrer.unselect();
            if (settings.callback) {
                settings.callback(false);
            }
        }
    });
}
...
}

用于加载 div 的 css 类似于:

#loadinginprogress {
    -webkit-border-radius: 10px;
    background-color: rgba(0,0,0,.5);
    color: white;
    font-size: 18px;
    font-weight: bold;
    height: 80px;
    left: 60px;
    line-height: 80px;
    margin: 0 auto;
    position: absolute;
    text-align: center;
    top: 120px;
    width: 200px;
    z-index: 5000;
}

showPageByHref() function in jqtouch js is a good start. i added it right into ajax call so the please wait will not flicker when you click on link that is already loaded etc.

In short - add loading div (id loadinginprogress in exmaple) right before the ajax call and remove later "success" or "error". the ajax call section would look something like that (shortened it ):

function showPageByHref(href, options) {
...
if (href != '#'){
    $('body').append('<div id="loadinginprogress">Loading...</div>');
    $.ajax({
        url: href,
        data: settings.data,
        type: settings.method,
        success: function (data, textStatus) {
            $('#loadinginprogress').remove()
            var firstPage = insertPages(data, settings.animation);
            if (firstPage)
            {
                if (settings.method == 'GET' && jQTSettings.cacheGetRequests && settings.$referrer)
                {
                    settings.$referrer.attr('href', '#' + firstPage.attr('id'));
                }
                if (settings.callback) {
                    settings.callback(true);
                }
            }
        },
        error: function (data) {
            $('#loadinginprogress').remove()
            if (settings.$referrer) settings.$referrer.unselect();
            if (settings.callback) {
                settings.callback(false);
            }
        }
    });
}
...
}

css for loading div would be something like:

#loadinginprogress {
    -webkit-border-radius: 10px;
    background-color: rgba(0,0,0,.5);
    color: white;
    font-size: 18px;
    font-weight: bold;
    height: 80px;
    left: 60px;
    line-height: 80px;
    margin: 0 auto;
    position: absolute;
    text-align: center;
    top: 120px;
    width: 200px;
    z-index: 5000;
}
撩起发的微风 2024-09-04 23:48:15

如果您的链接是 li class="arrow" 元素,这是基本行为。您如何显示链接以及您希望加载旋转器显示在哪里?

This is the basic behavior if your links are li class="arrow" elements. how are you displaying your links and where do you want the loading-spinner to display?

晌融 2024-09-04 23:48:15

感谢您的不同帖子。他们给了我很多帮助。

我有一个解决方案可以提出,无需修补 jQTouch 所依赖的 jQtouch 代码。
它使用 jQuery ajax 功能。


$(document).ready(function() {
...
  $('#jqt').ajaxStart(function() {
    console.log("ajaxStart");
    ...
  }).ajaxSuccess(function() {
    console.log("ajaxSuccess");
    ... 
  }).ajaxError(function() {
    console.log("ajaxError");
    .... 
  });
....
});

更多详细信息请参见此 jQuery 文档页面

Thank you for your different posts. They helped me a lot.

I have a solution to propose without patching the jQtouch code on which jQTouch relies.
It uses jQuery ajax capabilities.


$(document).ready(function() {
...
  $('#jqt').ajaxStart(function() {
    console.log("ajaxStart");
    ...
  }).ajaxSuccess(function() {
    console.log("ajaxSuccess");
    ... 
  }).ajaxError(function() {
    console.log("ajaxError");
    .... 
  });
....
});

more details available in this jQuery doc page.

绿萝 2024-09-04 23:48:15

您可以添加自定义事件处理程序,并在每次单击特定元素时触发loading.gif。

You could add a custom event handler, and trigger the loading.gif everytime the click on the specific element was done.

狼亦尘 2024-09-04 23:48:15

我刚刚回答了达林·帕克的问题。只要检查一下它可能会对您有所帮助。

I just answered Darin Parker's question. Just check it out it may help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文