Brak opisu

jquery.countUp.min.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. * jquery.counterup.js 1.0
  3. *
  4. * Copyright 2013, Benjamin Intal http://gambit.ph @bfintal
  5. * Released under the GPL v2 License
  6. *
  7. * Date: Nov 26, 2013
  8. */
  9. (function(e) {
  10. "use strict";
  11. e.fn.counterUp = function(t) {
  12. var n = e.extend({
  13. time: 400,
  14. delay: 10
  15. }, t);
  16. return this.each(function() {
  17. var t = e(this),
  18. r = n,
  19. i = function() {
  20. var e = [],
  21. n = r.time / r.delay,
  22. i = t.text(),
  23. s = /[0-9]+,[0-9]+/.test(i);
  24. i = i.replace(/,/g, "");
  25. var o = /^[0-9]+$/.test(i),
  26. u = /^[0-9]+\.[0-9]+$/.test(i),
  27. a = u ? (i.split(".")[1] || []).length : 0;
  28. for (var f = n; f >= 1; f--) {
  29. var l = parseInt(i / n * f);
  30. u && (l = parseFloat(i / n * f).toFixed(a));
  31. if (s)
  32. while (/(\d+)(\d{3})/.test(l.toString())) l = l.toString().replace(/(\d+)(\d{3})/, "$1,$2");
  33. e.unshift(l)
  34. }
  35. t.data("counterup-nums", e);
  36. t.text("0");
  37. var c = function() {
  38. t.text(t.data("counterup-nums").shift());
  39. if (t.data("counterup-nums").length) setTimeout(t.data("counterup-func"), r.delay);
  40. else {
  41. delete t.data("counterup-nums");
  42. t.data("counterup-nums", null);
  43. t.data("counterup-func", null)
  44. }
  45. };
  46. t.data("counterup-func", c);
  47. setTimeout(t.data("counterup-func"), r.delay)
  48. };
  49. t.waypoint(i, {
  50. offset: "100%",
  51. triggerOnce: !0
  52. })
  53. })
  54. }
  55. })(jQuery);