문제

Why is the percentage not stopping after the first animation. That being, right after the filling bar.

$('.perctext').delay(1500).each(
     function(a)
       $(this).delay(a*250).animate({
     'left':width
  },1000);
});

FIDDLE

What am I missing?

Thank you in advance.

SOLUTION: Check the answer from Blender bellow. FIDDLE WITH SOLUTION

도움이 되었습니까?

해결책

You're querying the DOM each time for elements that match your selector, so the first bar matches one element with a class of perctext, the second bar matches the previous bar's percentage text element and its own, and the third bar matches all three.

Store the created element in a variable and animate only that specific one

var $perctext = $('<div>', {'class': 'perctext', text: width});
$perctext.appendTo(this);

$perctext.delay(1500).each(function(a) {
    $(this).delay(a * 250).animate({
        'left': width
    }, 1000);
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top