在jquery上停止一个函数

时间:2018-01-28 13:09:49

标签: javascript jquery

我的jquery函数有问题。 当我启动我的页面时,我的进度条如预期的那样活跃起来,但是它们在没有停止的情况下变得活跃......我希望代码运行一次。 这是代码和功能。 非常感谢你的帮助。

这是代码

function loadBar() {
    var delay = 500;
    $(".progress-bar").each(function(i) {
        $(this).delay(delay * i).animate({
            width: $(this).attr('aria-valuenow') + '%'
        }, delay);

        $(this).prop('Counter', 0).animate({
            Counter: $(this).text()
        }, {
            duration: delay,
            easing: 'swing',
            step: function(now) {
                $(this).text(Math.ceil(now) + '%');
            }
        });
    });
}
$(document).ready(function() {
    // au clic sur un lien

    $('#webLangages').on('click', function() {

        loadBar();
    });
});


var target = $("#third").offset().top;
var interval = setInterval(function(event) {
    if ($(window).scrollTop() > target) {
        //start loading progress bar
        loadBar();
        loadBar.stopNow();
    }
}, 1000);

0 个答案:

没有答案