BIG

[javascript] jQuery 이용 1초 마다 class add / remove 샘플

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .focus{
            font-weight: bold;
        }
    </style>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<body>

<ul class="process">
    <li class="focus">가</li>
    <li>나</li>
    <li>다</li>
    <li>라</li>
    <li>마</li>
</ul>

</body>

<script>
    let now_li_idx  =   0;
    function func_test()
    {
        let obj_li  =   jQuery(".process li");
        console.log( obj_li.length );
        for(let loopCnt=0; obj_li.length>loopCnt; loopCnt++)
        {
            if( now_li_idx == loopCnt )
            {
                jQuery( obj_li[loopCnt] ).addClass("focus")
            }else{
                jQuery( obj_li[loopCnt] ).removeClass("focus")
            }
            //sleep(500);
        }// end for
        now_li_idx  = ( now_li_idx + 1 ) % 5;
        console.log( "now_li_idx:" + now_li_idx );
    }

    func_test();
    setInterval(func_test, 1000);
</script>

</html>
LIST