Dot dotdot dotdotdot as loading?

前端 未结 8 2160
借酒劲吻你
借酒劲吻你 2021-01-31 07:43

I wanna create some loading dots, like this:

At 0000 miliseconds the span content is: .

At 0100 miliseconds the span content is: ..

8条回答
  •  失恋的感觉
    2021-01-31 08:14

    With String.prototype.repeat() you can do:

    var element = document.querySelector(...);
    var counter = 0;
    
    var intervalId = window.setInterval(function() {
        counter += 1
        element.innerHTML = '.'.repeat(1 + counter % 3)
    }, 350);
    
    // Use the following to clear the interval
    window.clearInterval(intervalId)
    

    Note: String.prototype.repeat() is currently not supported in < IE11

提交回复
热议问题