jQuery GIF Animations

前端 未结 6 850
挽巷
挽巷 2021-01-05 23:16

I\'m looking to use jQuery to remove the need of using a GIF\'s to create a fairly simple animation.

What I want is an image to have four stages. 1) Nothing showing

6条回答
  •  Happy的楠姐
    2021-01-05 23:44

    This is much easier and maintains chain-ability:

    JQuery:

    $(document).ready(function(){
        //rotator - delay, children
        $('#slideshow').rotator(50, 'img');
    });
    

    Markup:

    
    
    
    
    
    
    

    Plugin:

    (function( $ ){
        $.fn.rotator = function(delay, child){
            //set curImage val
            var currImg = 0;
            var currIt = true;
            //set array of images
            var ss = $('#slideshow').children(child);
            var ssize = ss.size();
            setInterval(function() {
                if(currIt){
                    $(ss[currImg]).css('opacity','1');
                    currIt = !currIt;
                }else if (!currIt){
                    $(ss[currImg]).css('opacity','0');
                    $(ss[currImg+1]).css('opacity','1');
                    currIt = !currIt;
                    currImg++;
                }
                //reset
                if(currImg >= ssize){
                    currImg = 0;
                    $(ss[currImg]).css('opacity','1');
                }
            }, delay);
            return this;
        };
    })(jQuery);
    

提交回复
热议问题