如何为.css状态的更改添加延迟

How can I add a delay to a change of .css state

本文关键字:添加 延迟 状态 css      更新时间:2023-09-26

我有以下内容:

  $(document)
    .ajaxStart(function () {
        $(this).css({ 'cursor': 'progress !important' })
    })
    .ajaxStop(function () {
        $(this).css({ 'cursor': 'default !important' })
    });

有没有一种方法可以将光标进度状态延长2秒。现在它来得太快,去得太快。换句话说,我希望将光标更改为"progress"至少几秒钟。

编辑:

尝试使用window.setTimeout

  var timer = null;
  $(document)
    .ajaxStart(function () {
        if (timer) {
            clearTimeout(timer);
        }
        $(this).css({ 'cursor': 'progress !important' });
    })
    .ajaxStop(function () {
        timer = setTimeout(function() {
           $(this).css({ 'cursor': 'default !important' });
        }, 2000);
    });

像这样尝试

$(this).delay('1000').css({ 'cursor': 'progress !important' });

试试这个

$.delay(1000, function(){
//Do anything after 1 second
});

您可以使用setTimeout(http://www.w3schools.com/js/js_timing.asp);

setTimeout("javascript函数",毫秒);

在"javascript函数"中将毫秒替换为要等待的时间。