简体   繁体   English

javascript setInterval更改背景?

[英]Javascript setInterval change background?

I want to use javascript to make an element change it's background color to red when it is jumped to from a link further up the page. 我想使用javascript将元素从页面上的链接跳转到红色时将其背景颜色更改为红色。 Then after a second it should change back to white, to give a sort of flashing effect. 然后一秒钟后,它应该变回白色,以产生某种闪烁效果。 I've managed to get it to change to red then back to white, only it keeps on going! 我设法将其更改为红色,然后又变为白色,只有这样才能继续! Can anyone tell me how to make it flash just once? 谁能告诉我如何使其一次闪烁?

This is my javascript code... 这是我的JavaScript代码...

 function glow() {
        setInterval( function() {

        var see = document.getElementById("see");
        var run = document.getElementById("run");
        var enter = document.getElementById("enter");

            see.style.backgroundColor = 'red'; 
            run.style.backgroundColor = 'red';
            enter.style.backgroundColor = 'red';
            }, 400);

        setInterval( function() {
        var see = document.getElementById("see");
        var run = document.getElementById("run");
        var enter = document.getElementById("enter");

                see.style.backgroundColor = 'white'; 
                run.style.backgroundColor = 'white';
                enter.style.backgroundColor = 'white'; 
                } , 1000);
    }

将setInterval更改为setTimeout以仅执行一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM