Why doesn't Progress Bar dynamically change unlike Text?

后端 未结 6 1697
無奈伤痛
無奈伤痛 2021-02-07 06:56

I\'m dynamically updating a few elements after a setTimeout() function. The jQuery function .text() seems to dynamically update with each change of ind

6条回答
  •  自闭症患者
    2021-02-07 07:09

    Text and Progress Bar change dynamically, but with delay === 0 it's very fast: (http://jsfiddle.net/sergdenisov/mh4o1wxz/1/):

    HTML:

    Text

    Javascript:

    var delay = 0;
    var percent = 0;
    
    var iID = setInterval(function() {
        percent += 10;
        $('.text').text('Text ' + percent + '/100');
        $('.progress-bar').css('width', percent + '%').attr('aria-valuenow', percent);    
        if (percent === 100) {
            clearInterval(iID);
        }
    }, delay);
    

提交回复
热议问题