jQuery: Find word and change every few seconds

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

         $(document).ready(function(){ 
                    setInterval(function(){
                          var current = jQuery(".animate-span .active");
                          var cIndex = jQuery(".animate-span span").index(current), cLength = jQuery(".animate-span span").length, nextSpan = null;
                          if(cIndex<(cLength-1)){
                           nextSpan =   jQuery(".animate-span span").eq(cIndex+1)        
                           }else{
                         nextSpan = jQuery(".animate-span span").eq(0);
                    }
                         nextSpan.animate({top:0,opacity:1},500).addClass("active");
    
                          current.animate({top:45,opacity:0},500,function(){
                            jQuery(this).css({top:-40});
                        }).removeClass("active");
                    },2000)
                });   
    

    live demo here

提交回复
热议问题