.delay()在更改< div>的背景颜色时不工作 [英] .delay() not working when changing background-color of <div>

查看:127
本文介绍了.delay()在更改< div>的背景颜色时不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习JQUERY,我一直在玩弄延迟()我写了一个小提琴来显示你...我想做的是当一个按钮被点击,改变div的背景颜色然后过一会儿再次切换背景颜色。但是当我尝试它,它只是切换到第二种颜色,跳过第一个。

I am just learning JQUERY and I have been playing around with delay() I wrote a fiddle to show you... What I am trying to do is when a button is clicked, change the background-color of the div and then after a few moments switch the background color again. But when I try it, it just switches to the second color and skips the first.

HTML:

<div class = "animation">


</div> 

<button id = "change"> Click </button>

这里是Jquery代码:

Here is the Jquery code:

$(document).ready(function(){
$("#change").click(function(){

    $(".animation").css("background", "blue").delay(700).css("background", "red");


    });
});

以下是链接:

a href =http://jsfiddle.net/kPzYb/ =nofollow> JSFiddle

JSFiddle

推荐答案

延迟 仅适用于队列中的项目(例如动画) 。

delay only works for items in the queue (such as animations).

对于其他任何操作,请使用 a正常旧计时器

For anything else, use a regular old timer:

$("#change").click(function() {
    var $el = $(".animation");

    $el.css("background", "blue");

    setTimeout(function () {
        $el.css("background", "red");
    }, 700);
});

这篇关于.delay()在更改&lt; div&gt;的背景颜色时不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆