1 $.fn.countTo = function (options) { 2 options = options || {}; 3 return $(this).each(function () { 4 // set options for current element 5 var settings = $.extend({}, $.fn.countTo.defaults, { 6 from: $(this).data('from'), 7 to: $(this).data('to'), 8 speed: $(this).data('speed'), 9 refreshInterval: $(this).data('refresh-interval'), 10 decimals: $(this).data('decimals') 11 }, options); 12 // how many times to update the value, and how much to increment the value on each update 13 var loops = Math.ceil(settings.speed / settings.refreshInterval), 14 increment = (settings.to - settings.from) / loops; 15 // references & variables that will change with each update 16 var self = this, 17 $self = $(this), 18 loopCount = 0, 19 value = settings.from, 20 data = $self.data('countTo') || {}; 21 $self.data('countTo', data); 22 // if an existing interval can be found, clear it first 23 if (data.interval) { 24 clearInterval(data.interval); 25 } 26 data.interval = setInterval(updateTimer, settings.refreshInterval); 27 // initialize the element with the starting value 28 render(value); 29 function updateTimer() { 30 value += increment; 31 loopCount++; 32 render(value);
33 if (typeof(settings.onUpdate) == 'function') { 34 settings.onUpdate.call(self, value); 35 } 36 if (loopCount >= loops) { 37 // remove the interval 38 $self.removeData('countTo'); 39 clearInterval(data.interval); 40 value = settings.to; 41 if (typeof(settings.onComplete) == 'function') { 42 settings.onComplete.call(self, value); 43 } 44 } 45 } 46 function render(value) { 47 var formattedValue = settings.formatter.call(self, value, settings); 48 $self.text(formattedValue); 49 } 50 }); 51 }; 52 $.fn.countTo.defaults = { 53 from: 0, // the number the element should start at 54 to: 0, // the number the element should end at 55 speed: 1000, // how long it should take to count between the target numbers 56 refreshInterval: 100, // how often the element should be updated 57 decimals: 0, // the number of decimal places to show 58 formatter: formatter, // handler for formatting the value before rendering 59 onUpdate: null, // callback method for every time the element is updated 60 onComplete: null // callback method for when the element finishes updating 61 }; 62 function formatter(value, settings) { 63 return value.toFixed(settings.decimals); 64 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.