gpt4 book ai didi

jquery - 延迟 jquery css 更改

转载 作者:行者123 更新时间:2023-12-01 02:24:27 24 4
gpt4 key购买 nike

我编写了一段代码,使 div 的边框变为橙色,然后在一两秒后将其更改为黑色,但实际发生的情况是它直接变为黑色,请问有什么帮助吗?谢谢!

代码:

$('#newMessage1').css('border','2px solid #ffa800').delay(100).css('border','2px solid #000000');

最佳答案

jQuery delay 函数仅适用于添加到 fx 队列的函数(例如 fadeInslideDown 等函数) )。 css 不是这些函数之一(尝试延迟任何其他非fx队列感知函数,它也不会工作)。

来自docs :

Added to jQuery in version 1.4, 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.

jQuery delay 不能替代原生 JS setTimeout,在这种情况下,这可能是可行的方法。例如,您可以执行类似的操作(工作示例 here ):

$('#newMessage1').css('border','2px solid #ffa800');

setTimeout(function() {
$("#newMessage1").css('border','2px solid #000000');
}, 1000);

关于jquery - 延迟 jquery css 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6731971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com