Is there anyway to animate an ellipsis with CSS animations?

前端 未结 8 1060
情话喂你
情话喂你 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:33

    Short answer is "not really". However, you can play around with animating width and overflow hidden, and maybe get an effect that is "close enough". (code below tailored for firefox only, add vendor prefixes as needed).

    html

    Loading

    css

    .loading:after {
        overflow: hidden;
        display: inline-block;
        vertical-align: bottom;
        -moz-animation: ellipsis 2s infinite;
        content: "\2026"; /* ascii code for the ellipsis character */
    }
    @-moz-keyframes ellipsis {
        from {
            width: 2px;
        }
        to {
            width: 15px;
        }
    }
    

    demo: http://jsfiddle.net/MDzsR/1/

    edit

    It appears chrome has issues with animating the pseudo-element. An easy fix is to wrap the ellipsis in its own element. Check out http://jsfiddle.net/MDzsR/4/

提交回复
热议问题