js实现颜色闪烁效果

定时器控制背景色或者透明度html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>颜色闪缩</title>
    <script src="./jquery-3.3.1.js"> </script>
</head>
<body>
<div id="color_flash">
    <div class="lit_slashNum" style="width: 5px;height: 5px;border-radius: 5px;transition: all 0.5s; background-color: #0165bb;-moz-box-shadow:0px 0px 10px 2px #0165bb; -webkit-box-shadow:0px 0px 10px 2px #0165bb; box-shadow:0px 0px 10px 2px #0165bb;"></div>
</div>


</body>
<script>
    setInterval(changeColor,500);

    //js
    var colorFlag = 0;
    function changeColor() {
        let lit_slashNum = document.querySelector(".lit_slashNum");
        if (!colorFlag)
        {
            lit_slashNum.style.backgroundColor = '#0165bb';
            lit_slashNum.style.boxShadow = '0px 0px 10px 2px #0165bb';
            colorFlag = 1;
        }else{
            lit_slashNum.style.backgroundColor = '';
            lit_slashNum.style.boxShadow = '';
            colorFlag = 0;
        }
    }

    //jq
    function litSlash(){
        $(".lit_slashNum").animate(
            {opacity:"0"},250); //改变透明度
        $(".lit_slashNum").animate(
            {opacity:"1"},500);
    }
</script>
</html>

codepenjquery