【发布时间】:2014-10-24 07:08:29
【问题描述】:
我在 web 应用程序中使用 spin,它工作得很好,但在一种情况下,它不能。
在进行 ajax 调用之前,我调用函数 showLoading();
function showLoading() {
$('<div id="divSpin"></div>').appendTo(document.body);
var target = document.getElementById("divSpin");
var opts = {
lines: 13, // The number of lines to draw
length: 20, // The length of each line
width: 10, // The line thickness
radius: 30, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 8, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'mySpin', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to parent
};
if (mySpinner) mySpinner.spin(target);
else {
mySpinner = new Spinner(opts).spin(target);
}
}
在成功函数中我调用了removeLoading方法:
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(jsonObject),
contentType: "application/json; charset=utf-8",
dataType: 'json',
async: async
}).success(function (data, textStatus, jqXhr) {
callback(data);
removeLoading();
});
在 removeLoading 中我只调用 mySpinner.stop();
永远不会显示微调器。 ajax 调用需要一些时间才能完成(几秒钟),如果我使用 chrome 进行调试并设置断点,我会看到旋转已创建,即使我直接在 removeLoading-function 中设置断点也会显示旋转。
提前谢谢
©a-x-i
【问题讨论】:
-
创建一个有问题的 jsFiddle。我有一种感觉,你会在创作时自己解决它。
标签: javascript spinner spin.js