[英]How to make this change border color animation stop
Hi I found this code and I'm wondering how to make it stop blinking after 3 seconds 嗨,我找到了此代码,我想知道如何使其在3秒后停止闪烁
function flashit()
{
var myborder = document.getElementById('my');
if (myborder.style.borderColor=="green")
myborder.style.borderColor="red" ;
else
myborder.style.borderColor="green" ;
}
setInterval('flashit()', 400) ;
setTimeout
and setInterval
return an identifier that refers back to the timeout/interval; setTimeout
和setInterval
返回一个标识符,该标识符返回到超时/间隔; which can then later be used to unset them. 然后可以用来取消设置它们。
So I changed your code to demonstrate. 因此,我更改了代码以进行演示。 Please comment if you have any questions.
如有任何疑问,请发表评论。
function flashit(){
var myborder = document.getElementById('my');
if (myborder.style.borderColor=="green"){
myborder.style.borderColor="red" ;
} else {
myborder.style.borderColor="green" ;
}
}
var intervalId = setInterval(flashit, 400) ;
setTimeout(function() {
clearInterval(intervalId);
}, 3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.