ajax - 为什么 GIF 动画在执行 AJAX 调用时停止工作?

标签 ajax animation jquery-ui-dialog gif

我的目标是在执行 AJAX 调用时显示加载弹出窗口(其中包含 GIF)。 我正在使用 jQuery UI Modal dialog ,其中我使用 CSS 插入 GIF 动画。在 AJAX 调用开始之前,我打开对话框并在调用完成后立即关闭它。问题是当 AJAX 调用运行时 GIF 停止工作并且它发生在所有浏览器中。我正在使用以下代码:

<div id="loadingScreen" title="Loading">Please wait...</div>

#loadingScreen {
    background: url(http://regretless.com/stuff/jQuery/images/loading.gif) no-repeat 5px 8px;
    padding-left: 25px;
}

$("#loadingScreen").dialog('open');
setTimeout(function () {
  $.ajax({
    type: "GET",
    url: "testing.txt",
    async: true,
    dataType: "text",
    success: function (returnText) {
      $("#viewDescription").text(returnText);
      $("#viewGroupID").text(" " + t.id);
      $("#loadingScreen").dialog('close');
      $('#View').dialog('open');
    },
    error: function (xhr, status, error) {
      $("#loadingScreen").dialog('close');
      alert("An error has occured");
    }
  });
}, 10);

谁能告诉我可能是什么问题?

最佳答案

因为这是背景,所以您需要将焦点设置到#loadingScreen 以保持动画继续。

关于ajax - 为什么 GIF 动画在执行 AJAX 调用时停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11453277/

相关文章:

jquery - 将数组的结果相加即可得到总计

javascript - Php echo 返回两个额外的未知字符

html - 如何在我的 Html 页面中动态获取 Css 文件

css - 如何使 `react-beautiful-dnd` 不触发 `react-transition-group` 动画?

jQuery UI 对话框 - 对话框关闭 (x) 或取消后重置表单值和验证

java - Ember 支持 CORS 的 XDomainRequest(xdr)

css - 移动按钮推送内容

javascript - 我如何通过 javascript 为 css 代码运行这篇文章

javascript - 按钮克隆上不需要的点击事件

jquery - UI 对话框上的自动高度,如果高度更改,对话框将不再垂直居中