index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="robots" content="index,follow">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  8. <meta name="description" content="A javascript class that animates a numerical value by counting to it.">
  9. <title>CountUp.js</title>
  10. <!-- <link rel="stylesheet" type="text/css" href="../inorganik.github.io/assets/css/style.css?v=20140820"> -->
  11. <link rel="stylesheet" type="text/css" href="../assets/css/style.css?v=20141210">
  12. <!-- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script> -->
  13. <script src="countUp.js"></script>
  14. <!-- <script type="text/javascript" src="angular-countUp.js"></script> -->
  15. <script>
  16. //var app = angular.module("demoApp",["countUpModule"]);
  17. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  18. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  19. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  20. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  21. ga('create', 'UA-7742845-9', 'inorganik.github.io');
  22. ga('send', 'pageview');
  23. </script>
  24. </head>
  25. <body ng-app="demoApp">
  26. <a class="forkMe" href="https://github.com/inorganik/CountUp.js"><img src="../assets/img/forkme_custom_indigo.png" alt="Fork me on GitHub"></a>
  27. <div id="wrap">
  28. <header>
  29. <div id="github"><a class="block" href="https://github.com/inorganik"></a></div>
  30. <div class="leaderLine">////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div>
  31. <div id="logo"><a class="block" href="http://inorganik.github.io"></a></div>
  32. </header>
  33. <section>
  34. <h1>CountUp.js &nbsp;<small id="version" class="lt-gray"></small></h1>
  35. <p>CountUp.js is a dependency-free, lightweight JavaScript "class" that can be used to quickly create animations that display numerical data in a more interesting way.</p>
  36. <p>Install via npm using the package name <code class="indigo large">&nbsp;countup.js&nbsp;</code> or bower using <code class="indigo large">&nbsp;countUp.js</code>.</p>
  37. <h3 class="marginTop marginBottom"><a class="lime weight700" href="https://github.com/inorganik/CountUp.js">Download on Github</a></h3>
  38. </section>
  39. <section>
  40. <p style="position:absolute; top:5px; left:0;">Current stars:</p>
  41. <h1 class="jumbo" id="myTargetElement">0</h1>
  42. </section>
  43. <section>
  44. <form>
  45. <h4 class="inlineLeft noMargin weight300">Params:</h4>
  46. <div class="inlineLeft marginLeft marginRight">
  47. <input type="text" value="24.02" id="startVal" style="width:50px" onkeyup="updateCodeVisualizer()">
  48. <label class="inlineLabel">Start</label>
  49. </div>
  50. <input type="button" class="inlineLeft marginRight" value="Swap" onClick="swapValues()" style="width:80px;">
  51. <div class="inlineLeft marginRight">
  52. <input type="text" value="94.62" id="endVal" style="width:50px" onkeyup="updateCodeVisualizer()">
  53. <label class="inlineLabel">End</label>
  54. </div>
  55. <div class="inlineLeft marginRight">
  56. <input type="number" value="2" id="decimals" step="1" style="width:50px" onkeyup="updateCodeVisualizer()" onchange="updateCodeVisualizer()">
  57. <label class="inlineLabel">Decimals</label>
  58. </div>
  59. <div class="inlineLeft marginRight">
  60. <input type="number" value="2.5" id="duration" step=".1" style="width:50px" onkeyup="updateCodeVisualizer()" onchange="updateCodeVisualizer()">
  61. <label class="inlineLabel">Duration</label>
  62. </div>
  63. </form>
  64. </section>
  65. <section>
  66. <form>
  67. <h4 class="inlineLeft noMargin weight300">Options:</h4>
  68. <div class="inlineLeft marginLeft marginRight">
  69. <input type="checkbox" onClick="toggleEasing(this)" checked><label class="inlineLabel">Use easing</label>
  70. </div>
  71. <div class="inlineLeft marginRight">
  72. <input type="checkbox" onClick="toggleGrouping(this)" checked><label class="inlineLabel">Use grouping</label>
  73. </div>
  74. <div class="inlineLeft marginRight">
  75. <input type="text" value="," id="separator" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  76. <label class="inlineLabel">Separator</label>
  77. </div>
  78. <div class="inlineLeft marginRight">
  79. <input type="text" value="." id="decimal" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  80. <label class="inlineLabel">Decimal</label>
  81. </div>
  82. <div class="inlineLeft marginRight">
  83. <input type="text" value="" id="prefix" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  84. <label class="inlineLabel">Prefix</label>
  85. </div>
  86. <div class="inlineLeft marginRight">
  87. <input type="text" value="" id="suffix" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  88. <label class="inlineLabel">Suffix</label>
  89. </div>
  90. </form>
  91. </section>
  92. <section>
  93. <form>
  94. <h4 class="inlineLeft noMargin weight300">Methods:</h4>
  95. <input type="button" value="Start" onClick="createCountUp()" class="inlineLeft marginLeft marginRight">
  96. <input type="button" value="Pause/Resume" onClick="showCodeAndPauseResume()" class="inlineLeft marginRight">
  97. <input type="button" value="Reset" onClick="showCodeAndReset()" class="inlineLeft marginRight">
  98. <input type="button" value="Update:" onClick="showCodeAndUpdate()" class="inlineLeft" style="margin-right:2px">
  99. <div class="inlineLeft marginRight">
  100. <input type="text" value="6789" id="updateVal" style="width:50px" onkeyup="updateCodeVisualizerForUpdate()">
  101. </div>
  102. <input type="checkbox" onClick="toggleOnComplete(this)"><label class="inlineLabel">Alert on complete</label>
  103. </form>
  104. </section>
  105. <section id="easingSection">
  106. <form>
  107. <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
  108. <div class="inlineLeft marginLeft">
  109. <select id="easingFnsDropdown" class="marginRight">
  110. <option value="easeOutExpo" selected>easeOutExpo (default, built-in)</option>
  111. <option value="outQuintic">outQuintic</option>
  112. <option value="outCubic">outCubic</option>
  113. </select>
  114. <input type="button" value="Apply easing" onClick="createCountUp()">
  115. </div>
  116. </form>
  117. </section>
  118. <section class="marginBottom">
  119. <div class="col full marginBottom marginTop">
  120. <div class="code-contain marginBottom">
  121. <code id="codeVisualizer" class="indigo">var options = {<br>
  122. &emsp;&emsp;useEasing : true, <br>
  123. &emsp;&emsp;easingFn : null, <br>
  124. &emsp;&emsp;useGrouping : true, <br>
  125. &emsp;&emsp;separator : ',', <br>
  126. &emsp;&emsp;decimal : '.' <br>
  127. }<br>
  128. var demo = new CountUp("myTargetElement", 24.02, 94.62, 0, 2, options);<br>
  129. demo.start();
  130. </code>
  131. </div>
  132. </div>
  133. </section>
  134. </div>
  135. </body>
  136. <script type="text/javascript">
  137. // set CountUp options
  138. // you don't need to do this - you can use the default options
  139. var useOnComplete = false,
  140. useEasing = true,
  141. easingFn = null,
  142. useGrouping = true,
  143. options = {
  144. useEasing : useEasing, // toggle easing
  145. easingFn : easingFn, // defaults to easeOutExpo, but you can specify your own
  146. useGrouping : useGrouping, // 1,000,000 vs 1000000
  147. separator : ',', // character to use as a separator
  148. decimal : '.', // character to use as a decimal
  149. };
  150. var demo, code, data, stars, easingFunctions;
  151. // create instance
  152. window.onload = function() {
  153. // setup CountUp object
  154. demo = new CountUp('myTargetElement', 0, 94.62, 2, 2.5, options);
  155. // you could do demo.start() right here but we are getting actual current star count from github api below
  156. // since it is an asynchronous call, we fire start() in the success fn of the XMLHttpRequest object
  157. getStars.send();
  158. // display version (no hassling with markup!)
  159. document.getElementById('version').innerHTML = 'v'+demo.version();
  160. };
  161. easingFunctions = {
  162. easeOutExpo: function(t, b, c, d) {
  163. return c * (-Math.pow(2, -10 * t / d) + 1) * 1024 / 1023 + b;
  164. },
  165. outQuintic: function(t, b, c, d) {
  166. var ts = (t /= d) * t;
  167. var tc = ts * t;
  168. return b + c * (tc * ts + -5 * ts * ts + 10 * tc + -10 * ts + 5 * t);
  169. },
  170. outCubic: function(t, b, c, d) {
  171. var ts = (t /= d) * t;
  172. var tc = ts * t;
  173. return b + c * (tc + -3 * ts + 3 * t);
  174. }
  175. };
  176. // for demo:
  177. function swapValues() {
  178. var oldStartVal = document.getElementById("startVal").value;
  179. var oldEndVal = document.getElementById("endVal").value;
  180. document.getElementById("startVal").value = oldEndVal;
  181. document.getElementById("endVal").value = oldStartVal;
  182. updateCodeVisualizer();
  183. }
  184. function getEasingFn() {
  185. var fn = document.getElementById("easingFnsDropdown").value;
  186. if (fn === 'easeOutExpo') return null;
  187. if (typeof easingFunctions[fn] === 'undefined') return undefined;
  188. return easingFunctions[fn];
  189. }
  190. function getEasingFnBody(fn) {
  191. fn = typeof fn === 'undefined' ? getEasingFn() : fn;
  192. if (typeof fn === 'undefined') return 'undefined function';
  193. if (fn !== null) {
  194. return fn.toString().replace(/^ {8}/gm, '');
  195. }
  196. return '';
  197. }
  198. function createCountUp() {
  199. var startVal = document.getElementById("startVal").value;
  200. startVal = Number(startVal.replace(',','').replace(' ',''));
  201. var endVal = document.getElementById("endVal").value;
  202. endVal = Number(endVal.replace(',','').replace(' ',''));
  203. var decimals = document.getElementById("decimals").value,
  204. duration = document.getElementById("duration").value,
  205. prefix = document.getElementById("prefix").value,
  206. suffix = document.getElementById("suffix").value,
  207. easingFn = getEasingFn();
  208. options = {
  209. useEasing : useEasing,
  210. easingFn : typeof easingFn === 'undefined' ? null : easingFn,
  211. useGrouping : useGrouping,
  212. separator : document.getElementById("separator").value,
  213. decimal : document.getElementById("decimal").value,
  214. prefix: prefix,
  215. suffix: suffix
  216. };
  217. // you don't have to create a new instance of CountUp every time you start an animation,
  218. // you can just change the properties individually. But I do here in case user changes values in demo.
  219. demo = new CountUp("myTargetElement", startVal, endVal, decimals, duration, options);
  220. if (useOnComplete) {
  221. demo.start(methodToCallOnComplete);
  222. } else {
  223. demo.start();
  224. }
  225. updateCodeVisualizer();
  226. }
  227. function showCodeAndPauseResume() {
  228. code = 'demo.pauseResume();';
  229. document.getElementById("codeVisualizer").innerHTML = code;
  230. demo.pauseResume();
  231. }
  232. function showCodeAndReset() {
  233. code = 'demo.reset();';
  234. document.getElementById("codeVisualizer").innerHTML = code;
  235. demo.reset();
  236. }
  237. function showCodeAndUpdate() {
  238. var updateVal = document.getElementById("updateVal").value;
  239. var num = updateVal ? updateVal : 0;
  240. demo.update(num);
  241. }
  242. function toggleOnComplete(checkbox) {
  243. if (checkbox.checked) {
  244. useOnComplete = true;
  245. } else {
  246. useOnComplete = false;
  247. }
  248. updateCodeVisualizer();
  249. }
  250. function toggleEasing(checkbox) {
  251. var easingSection = document.getElementById("easingSection");
  252. if (checkbox.checked) {
  253. useEasing = true;
  254. easingSection.style.display = "";
  255. document.getElementById("easingFnsDropdown").value = "easeOutExpo";
  256. document.getElementById("easingFnPreview").value = "";
  257. } else {
  258. useEasing = false;
  259. easingSection.style.display = "none";
  260. }
  261. updateCodeVisualizer();
  262. }
  263. function toggleGrouping(checkbox) {
  264. if (checkbox.checked) {
  265. useGrouping = true;
  266. } else {
  267. useGrouping = false;
  268. }
  269. updateCodeVisualizer();
  270. }
  271. function methodToCallOnComplete() {
  272. console.log('COMPLETE!');
  273. alert('COMPLETE!');
  274. }
  275. function updateCodeVisualizer() {
  276. var startVal = document.getElementById("startVal").value;
  277. startVal = Number(startVal.replace(',','').replace(' ',''));
  278. var endVal = document.getElementById("endVal").value;
  279. endVal = Number(endVal.replace(',','').replace(' ',''));
  280. var decimals = document.getElementById("decimals").value;
  281. var duration = document.getElementById("duration").value;
  282. var separator = document.getElementById("separator").value;
  283. var decimal = document.getElementById("decimal").value;
  284. var prefix = document.getElementById("prefix").value;
  285. var suffix = document.getElementById("suffix").value;
  286. var easingFn = getEasingFn();
  287. var easingFnBody = getEasingFnBody(easingFn);
  288. var code = '';
  289. if (useEasing && easingFn) {
  290. code += 'var easingFn = ';
  291. var split = easingFnBody.split('\n');
  292. for (var line in split) {
  293. code += split[line].replace(' ', '&nbsp;') + '<br>';
  294. }
  295. }
  296. code += 'var options = {<br>';
  297. code += (useEasing) ? '&emsp;&emsp;useEasing : true, <br>' : '&emsp;&emsp;useEasing : false, <br>';
  298. code += (easingFn && useEasing) ? '&emsp;&emsp;easingFn: easingFn, <br>' : '';
  299. code += (useGrouping) ? '&emsp;&emsp;useGrouping : true, <br>' : '&emsp;&emsp;useGrouping : false, <br>';
  300. code += '&emsp;&emsp;separator : \''+separator+'\', <br>';
  301. code += '&emsp;&emsp;decimal : \''+decimal+'\', <br>';
  302. code += '&emsp;&emsp;prefix : \''+prefix+'\', <br>';
  303. code += '&emsp;&emsp;suffix : \''+suffix+'\' <br>';
  304. code += '};<br>';
  305. code += 'var demo = new CountUp("myTargetElement", '+startVal+', '+endVal+', '+decimals+', '+duration+', options);<br>';
  306. if (useOnComplete) {
  307. code += 'demo.start(methodToCallOnComplete);';
  308. } else {
  309. code += 'demo.start();';
  310. }
  311. document.getElementById("codeVisualizer").innerHTML = code;
  312. }
  313. function updateCodeVisualizerForUpdate() {
  314. var updateVal = document.getElementById("updateVal").value;
  315. var num = updateVal ? updateVal : 0;
  316. code = 'demo.update(' + updateVal + ');';
  317. document.getElementById("codeVisualizer").innerHTML = code;
  318. }
  319. // get current star count
  320. var repoInfoUrl = 'https://api.github.com/repos/inorganik/CountUp.js';
  321. var getStars = new XMLHttpRequest();
  322. getStars.open('GET', repoInfoUrl, true);
  323. getStars.timeout = 5000;
  324. getStars.onreadystatechange = function() {
  325. // 2: received headers, 3: loading, 4: done
  326. if (getStars.readyState == 4) {
  327. if (getStars.status == 200) {
  328. if (getStars.responseText !== 'undefined') {
  329. if (getStars.responseText.length > 0) {
  330. data = JSON.parse(getStars.responseText);
  331. stars = data.stargazers_count;
  332. // change input values
  333. document.getElementById("startVal").value = 0;
  334. document.getElementById("endVal").value = stars;
  335. document.getElementById("decimals").value = 0;
  336. // change code example values
  337. updateCodeVisualizer();
  338. // change the startVal and endVal properties of the demo CountUp and run it
  339. demo.startVal = 0;
  340. demo.endVal = stars;
  341. demo.decimals = 0;
  342. demo.start();
  343. }
  344. }
  345. }
  346. }
  347. }
  348. getStars.onerror = function() {
  349. console.log('error: '+getStars.status)
  350. demo.start();
  351. }
  352. </script>
  353. </html>