jQuery: Find word and change every few seconds

后端 未结 6 1211
[愿得一人]
[愿得一人] 2021-01-03 00:12

How can I change a word every 2-3 seconds using jQuery?

For example:

I have this:

This is so <
6条回答
  •  青春惊慌失措
    2021-01-03 01:01

    You can easily do this using setInterval and few lines of code.

    Working demo

    var keywords = ["awesome", "cool", "fantastic", "incredible"];
    var count = 1;
    setInterval(function(){    
        $("span.keyword").fadeOut(400, function(){        
            $(this).html(keywords[count]);        
            count++;        
            if(count == keywords.length)            
                count = 0;        
            $(this).fadeIn(400);    
        });
    }, 2000);
    

提交回复
热议问题