div上有颜色变化的链动画,我想做'如果div没有改变颜色3秒,做点什么' 如何用颜色检查时间?
答案 0 :(得分:2)
假设您只调用此函数来更改颜色:
var timeoutId;
function changeColor(el, col, secs) {
if (timeoutId) {
clearTimeout(timeoutId);
}
// change color logic
el.style.backgroundColor = col;
// check
timeoutId = setTimeout(function() {
// do something
alert('color has not changed within ' + secs + ' seconds');
}, secs * 1000);
}