javascript - 我在 jQuery 中的任何延迟都不起作用

标签 javascript jquery html title

我的脚本:

$(function () {
    $("body").addClass("lost");

    var counter = 0;
    var time = 400;
    var delay = time*5+250;

    if($("body").hasClass("lost")) {
        $("nav").delay(delay).css({'background': 'transparent'});
        $("nav").delay(delay).css({'background-color': '#e30'});
        $(this).find(".slogan").delay(delay).html('USB-stick  is lost');
        var title = "this USB-stick is lost";
    } else {
        var title = "this USB-stick is not lost";
        $(this).find(".slogan").delay(delay).html('USB-stick is not lost');
    }

    var titleTimerId = setInterval(function(){
        document.title = document.title + '.';
        counter++;
        if(counter == 5){
            clearInterval(titleTimerId);
            document.title = title;
        }
    }, time);
});

我想要达到的是,在达到 var 延迟时间后所有内容都发生了变化,并且标题发生了变化,我已经将其放置在脚本的某些元素中,但这对我不起作用

这代表导航:

<nav onclick="window.location=''">
    <img src="//sakesalverda.nl/logo.png" alt="badge html 5" class="logo_nav"/>
    <p>sakesalverda.nl</p>
    <h1 class="slogan">USB-stick</h1>
</nav>

最佳答案

来自 jQuery docs :

the .delay() method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms of .show() or .hide() which do not use the effects queue.

css()html() 方法不使用队列,您需要用 queue() 包装它们方法,例如:

$("nav")
    .delay(delay)
    .queue(function (next) {
        $(this).css({'background': 'transparent'});
        next();
    });

关于javascript - 我在 jQuery 中的任何延迟都不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23720647/

相关文章:

javascript - 我想在表单中使用相同的按钮首先添加元素然后删除元素

javascript - 如何下载/保存 PHP 生成的 HTML 页面的内容?

javascript - 在 javascript 中使用 array.map() 内部的异步方法

Javascript - 如何从类中调用类中的函数?

调用服务器端方法的 Javascript 函数不起作用

php - 使用ajax提交登录表单时无法设置php session ?

javascript - 检测滚动元素之间的距离

javascript - this.style.display = 无; Google Chrome 中的问题 - HTML5

php - 使用PHP将SQL组名称用作表标题行

javascript - CSS 从特定点开始缩放,而该点可能会沿途发生变化?