2

나는 특정 양에 도달 할 때까지 카운터를 1 씩 증가시키기 위해 실행중인 간단한 코드를 가지고 있습니다.jQuery Counter IE에서 작동하지 않는 함수 <8

코드는 Chrome/FF/IE9 +에서 정상적으로 작동하지만 IE7/8에서는 £ 1.80에 도달하고 실행이 중지됩니다.

나는 그 해답을 찾을 수없는 것처럼 보일 수 있지만 분명히 일정한 양의 시간이 흐른 다음 중단됩니다.

주요 기능은 다음과

 (function($) { 
      $.fn.countTo = function(options) { 
       options = $.extend({}, $.fn.countTo.defaults, options || {}); 
       var loops = Math.ceil(options.speed/options.refresh_interval), 
        increment = (options.to - options.from)/loops; 
       return $(this).each(function() { 
        var _this = this, 
         loop_count = 0, 
         value = options.from, 
         interval = setInterval(update_timer, options.refresh_interval); 
        function update_timer() { 
         value += increment; 
         loop_count++; 
         if(options.format == 'money') { 
          $(_this).html('\u00A3' + number_with_commas(value.toFixed(options.decimals))); 
         } else { 
          $(_this).html(value.toFixed(options.decimals)); 
         } 
         if(typeof(options.on_update) == 'function') { 
          options.on_update.call(_this, value); 
         } 
         if(loop_count >= loops) { 
          clearInterval(interval); 
          value = options.to; 
          if(typeof(options.on_complete) == 'function') { 
           options.on_complete.call(_this, value); 
          } 
         } 
        } 
       }); 
      }; 
      $.fn.countTo.defaults = { 
       from: 0, // the number the element should start at 
       to: 100, // the number the element should end at 
       speed: 1000, // how long it should take to count between the target numbers 
       refresh_interval: 100, // how often the element should be updated 
       decimals: 2, // the number of decimal places to show 
       on_update: null, // callback method for every time the element is updated, 
       on_complete: null // callback method for when the element finishes updating 
      }; 
     })(jQuery); 

예는 다음 http://jsfiddle.net/yxEaN/

감사합니다.

+2

콘솔에 오류가 있습니까? –

+0

죄송합니다, 언급하지 않으 셨습니다 - 콘솔 오류 없음 – Ryan

+0

콜백 중 하나가 실패 할 수 있습니까? – cfs

답변

1

IE에서 문제가 해결되었습니다. 아래 코드를 확인하십시오

function number_with_commas(x) { 
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); 
} 

$.ajaxSetup ({ 
    // Disable caching of AJAX responses */ 
    cache: false 
}); 

(function($) 
{ 
$.fn.countTo = function(options) { 
    options = $.extend({}, $.fn.countTo.defaults, options || {}); 
    var loops = Math.ceil(options.speed/options.refresh_interval), 
     increment = (options.to - options.from)/loops; 
    return $(this).each(function() { 
     var _this = this, 
      loop_count = 0, 
      value = options.from, 
      interval = setInterval(function(){ 
       value += increment; 
       loop_count++; 
       if(options.format == 'money') { 
        $(_this).html('\u00A3' + number_with_commas(value.toFixed(options.decimals))); 
       } else { 
        $(_this).html(value.toFixed(options.decimals)); 
       } 
       if(typeof(options.on_update) == 'function') { 
        options.on_update.call(_this, value); 
       } 
       if(loop_count >= loops) { 
        clearInterval(interval); 
        value = options.to; 
        if(typeof(options.on_complete) == 'function') { 
         options.on_complete.call(_this, value); 
        } 
       } 

       },100); 

    }); 
}; 

$.fn.countTo.defaults = { 
    from: 0, 
    to: 100, 
    speed: 1000, 
    refresh_interval: 100, 
    decimals: 2, 
    on_update: null, 
    on_complete: null 
}; 
})(jQuery); 

$(function($) { 
    $('#total_charity_counter').countTo({ 
    format: 'money', 
    from: 0, 
    to: 4229.01, 
    speed: (4229.01/180), 
    refresh_interval: .01, 
    on_complete: function(value) { 
    $(this).hide().fadeIn(1000); 
} 
    }); 
});