在Javascript中停止闪烁功能 [英] Stop Blink functionality in Javascript

查看:99
本文介绍了在Javascript中停止闪烁功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我想在javascript中为DIV实现Blink功能。

我通过使用ajax成功了我使用的代码是

Hi Friends,

I want to implement Blink functionality for DIV in javascript.
I succeed the same by using ajax, the code that I used is

function getData_callback(res) {
    var result = res.value;
    if (result == 1) {
        isWtngEnable = true;
        intrvl = setInterval(function blinkDIV() {
            $("#dtWtngTime").css("background-color", function () {
                this.color = !this.color;
                return this.color ? "yellow" : "";
            });
        }, 200)
    }
    else {
        isWtngEnable = false;
        clearInterval(intrvl);
        $("#dtWtngTime").css("background-color", "");
    }
}



这里当结果为1时,闪烁按预期工作,但当结果不是1时继续眨眼。我不知道如何停止setInterval函数。



预期:一旦结果不是1,div背景颜色应为空一次。



但如果我刷新页面突然停止闪烁。



任何提示非常感谢。



谢谢,

RK


Here when result is 1, blinking is working as expected, but when result is not 1 it keeps on blinking. I dont know how to stop setInterval function.

Expected: Once result is not 1, div background color should be empty at once.

But if I refresh the page blinking stops suddenly.

Any tips will be greatly appreciated.

Thanks,
RK

推荐答案

#dtWtngTime)。css( background-color,function(){
this .color =!this.color ;
返回 .color? 黄色 ;
});
}, 200
}
其他 {
isWtngEnable = false ;
clearInterval(intrvl);
("#dtWtngTime").css("background-color", function () { this.color = !this.color; return this.color ? "yellow" : ""; }); }, 200) } else { isWtngEnable = false; clearInterval(intrvl);


#dtWtngTime).css( background-color );
}
}
("#dtWtngTime").css("background-color", ""); } }



这里当结果为1时,闪烁按预期工作,但当结果不是1时继续眨眼。我不知道如何停止setInterval函数。



预期:一旦结果不是1,div背景颜色应为空一次。



但如果我刷新页面突然停止闪烁。



任何提示非常感谢。



谢谢,

RK


Here when result is 1, blinking is working as expected, but when result is not 1 it keeps on blinking. I dont know how to stop setInterval function.

Expected: Once result is not 1, div background color should be empty at once.

But if I refresh the page blinking stops suddenly.

Any tips will be greatly appreciated.

Thanks,
RK


朋友,



花了差不多7小时后,我找到了符合我要求的替代解决方案。

这是我用过的代码

Friends,

After spending almost 7 hrs, I found alternate solution for my requirement.
This is the code I have used
function getData_callback(res) {
    var result = res.value;
    if (result == 1) {
        isWtngEnable = true;
        blinkDIVOn();
    }
    else {
        isWtngEnable = false;
        clearTimeout(timer);
        document.getElementById("dtWtngTime").style.background = "";
    }
}

function blinkDIVOn() {
    if (timer) clearTimeout(timer);

    document.getElementById("dtWtngTime").style.background = "Yellow"
    timer = setTimeout("blinkDIVOff()", 500);
}

function blinkDIVOff() {
    if (timer) clearTimeout(timer);

    document.getElementById("dtWtngTime").style.background = "";
    timer = setTimeout("blinkDIVOn()", 500);
}



现在闪烁立刻开始和完全停止。



谢谢各位朋友。



问候,

RK


Now blinking starts and stops perfectly at once.

Thanks friends.

Regards,
RK


这篇关于在Javascript中停止闪烁功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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