Is there anyway to animate an ellipsis with CSS animations?

前端 未结 8 1056
情话喂你
情话喂你 2021-01-29 22:58

I\'m trying to have an ellipsis animate, and was wondering if it was possible with CSS animations...

So it might be like

Loading...
Loading..
Loading.
Lo         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 23:16

    Well Actually there is a pure CSS way of doing this.

    I got the example from CSS Tricks, but made it also to be supported in Internet Explorer (I have tested it in 10+).

    Check the Demo: http://jsfiddle.net/Roobyx/AT6v6/2/

    HTML:

    Searching . . .

    CSS:

    @-webkit-keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    
    @-moz-keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
    
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    
    @-webkit-keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    
    @-moz-keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    
    @-o-keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    
    @keyframes opacity {
      0% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
        opacity: 1;
      }
      100% {
        filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
        opacity: 0;
      }
    }
    #searching-ellipsis span {
      -webkit-animation-name: opacity;
      -webkit-animation-duration: 1s;
      -webkit-animation-iteration-count: infinite;
      -moz-animation-name: opacity;
      -moz-animation-duration: 1s;
      -moz-animation-iteration-count: infinite;
      -ms-animation-name: opacity;
      -ms-animation-duration: 1s;
      -ms-animation-iteration-count: infinite;
    }
    #searching-ellipsis span:nth-child(2) {
      -webkit-animation-delay: 100ms;
      -moz-animation-delay: 100ms;
      -ms-animation-delay: 100ms;
      -o-animation-delay: 100ms;
      animation-delay: 100ms;
    }
    #searching-ellipsis span:nth-child(3) {
      -webkit-animation-delay: 300ms;
      -moz-animation-delay: 300ms;
      -ms-animation-delay: 300ms;
      -o-animation-delay: 300ms;
      animation-delay: 300ms;
    }
    

提交回复
热议问题