2015-01-23 6 views
0

웨이 포인트 호출 및 그래프 막대 기능에 대한 JS가 있습니다. 그것은 웨이 포인트에 도달 할 때마다 반복되며, 웨이 포인트가 이미 반복 기능을하지 않을 때까지 도달했음을 인식하고 싶습니다. 당신의 도움을 주셔서 감사합니다. :)일단 웨이 포인트에 도달하면 기능을 반복하지 않음

$.getScript('http://imakewebthings.com/jquery-waypoints/waypoints.min.js', function() { 

    $('#jack_bellamy').waypoint(function() { 
     setTimeout(function start(){ 

     $('.bar').each(function(i) 
     { 
     var $bar = $(this); 
     $(this).append('<span class="count"></span>') 
     setTimeout(function(){ 
      $bar.css('width', $bar.attr('data-percent'));  
     }, i*100); 
     }); 

    $('.count').each(function() { 
     $(this).prop('Counter',0).animate({ 
      Counter: $(this).parent('.bar').attr('data-percent') 
     }, { 
      duration: 2000, 
      easing: 'swing', 
      step: function (now) { 
       $(this).text(Math.ceil(now) +'%'); 
      } 
     }); 
    }); 

    }, 500) 

    }); 
    }); 

답변

3

당신은 당신이 그것을 destroy 수 트리거 유지하는 웨이 포인트를하지 않으려면. 한 번만 실행되도록하려면 처리기가 끝날 때이를 제거 할 수 있습니다. 키워드는 처리기 내에서 파기 할 수있는 웨이 포인트 인스턴스를 나타냅니다.

$('#jack_bellamy').waypoint(function() { 
    // all that animation stuff you mentioned 
    this.destroy(); 
});