JS's questions about project timers

1. There is a requirement to write a dynamic display container, which is displayed every five seconds, and then closed in three seconds. And then it goes on and on.
my idea is to write a setInterval that can be displayed every five seconds, but the display is turned off in three seconds. How to write this requirement? ask experienced friends to share their ideas

.
Apr.05,2021

add a timeout to interval

setInterval(()=>{
    show=true;
    setTimeout(()=>{
        show=false;
    },3000)
},5000)

write two timers, start the first timer first, stop the current timer when the time is 5 seconds, and start another 3-second timer at the same time. Similarly, your container needs to be judged according to the Bool value. In these two timers, the bound Bool value is judged by time


<style>
    .demobox{
        display: none;
    }
</style>
<body>
    <div class="demobox">
        
    </div>
</body>

<script>
    $(function () {
        showFun()
    })

    function showFun() {
        setTimeout(hideFun, 5000)
    }
    function hideFun() {
        $('.demobox').show();
        setTimeout(function () {
            $('.demobox').hide();
            showFun();
        }, 3000)

    }
</script>

<body>
    <div class="demobox">
        
    </div>
</body>
<script>
//web
    function hidefun(){
        setTimeout(showfun,3000);
    };
    function showfun(){
        $('.demobox').hide();
        setTimeout(function(){
            $('.demobox').show();
            hidefun();
        },5000);
    }
    hidefun();
</script>
.
Menu