jQuery: Find word and change every few seconds

后端 未结 6 1170
[愿得一人]
[愿得一人] 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:07

    (function(){
    
        // List your words here:
        var words = [
            'awesome',
            'incredible',
            'cool',
            'fantastic'
            ], i = 0;
    
        setInterval(function(){
            $('#changerificwordspanid').fadeOut(function(){
                $(this).html(words[i=(i+1)%words.length]).fadeIn();
            });
           // 2 seconds
        }, 2000);
    
    })();
    

    Give your span an id, and change changerificwordspanid to the id of the span.

    JSFiddle Example here

提交回复
热议问题