index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. <!--<h1 class="jumbo" count-up start-val="0" end-val="2536.1" duration="2.5" decimals="1"></h1>-->
  43. </section>
  44. <section>
  45. <form>
  46. <h4 class="inlineLeft noMargin weight300">Params:</h4>
  47. <div class="inlineLeft marginLeft marginRight">
  48. <input type="text" value="24.02" id="startVal" style="width:50px" onkeyup="updateCodeVisualizer()">
  49. <label class="inlineLabel">Start</label>
  50. </div>
  51. <input type="button" class="inlineLeft marginRight" value="Swap" onClick="swapValues()" style="width:80px;">
  52. <div class="inlineLeft marginRight">
  53. <input type="text" value="94.62" id="endVal" style="width:50px" onkeyup="updateCodeVisualizer()">
  54. <label class="inlineLabel">End</label>
  55. </div>
  56. <div class="inlineLeft marginRight">
  57. <input type="number" value="2" id="decimals" step="1" style="width:50px" onkeyup="updateCodeVisualizer()" onchange="updateCodeVisualizer()">
  58. <label class="inlineLabel">Decimals</label>
  59. </div>
  60. <div class="inlineLeft marginRight">
  61. <input type="number" value="2.5" id="duration" step=".1" style="width:50px" onkeyup="updateCodeVisualizer()" onchange="updateCodeVisualizer()">
  62. <label class="inlineLabel">Duration</label>
  63. </div>
  64. </form>
  65. </section>
  66. <section>
  67. <form>
  68. <h4 class="inlineLeft noMargin weight300">Options:</h4>
  69. <div class="inlineLeft marginLeft marginRight">
  70. <input type="checkbox" onClick="toggleEasing(this)" checked><label class="inlineLabel">Use easing</label>
  71. </div>
  72. <div class="inlineLeft marginRight">
  73. <input type="checkbox" onClick="toggleGrouping(this)" checked><label class="inlineLabel">Use grouping</label>
  74. </div>
  75. <div class="inlineLeft marginRight">
  76. <input type="text" value="," id="separator" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  77. <label class="inlineLabel">Separator</label>
  78. </div>
  79. <div class="inlineLeft marginRight">
  80. <input type="text" value="." id="decimal" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  81. <label class="inlineLabel">Decimal</label>
  82. </div>
  83. <div class="inlineLeft marginRight">
  84. <input type="text" value="" id="prefix" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  85. <label class="inlineLabel">Prefix</label>
  86. </div>
  87. <div class="inlineLeft marginRight">
  88. <input type="text" value="" id="suffix" style="width:15px; padding:0 5px;" onkeyup="updateCodeVisualizer()">
  89. <label class="inlineLabel">Suffix</label>
  90. </div>
  91. </form>
  92. </section>
  93. <section>
  94. <form>
  95. <h4 class="inlineLeft noMargin weight300">Methods:</h4>
  96. <input type="button" value="Start" onClick="createCountUp()" class="inlineLeft marginLeft marginRight">
  97. <input type="button" value="Pause/Resume" onClick="showCodeAndPauseResume()" class="inlineLeft marginRight">
  98. <input type="button" value="Reset" onClick="showCodeAndReset()" class="inlineLeft marginRight">
  99. <input type="button" value="Update:" onClick="showCodeAndUpdate()" class="inlineLeft" style="margin-right:2px">
  100. <div class="inlineLeft marginRight">
  101. <input type="text" value="6789" id="updateVal" style="width:50px" onkeyup="updateCodeVisualizerForUpdate()">
  102. </div>
  103. <input type="checkbox" onClick="toggleOnComplete(this)"><label class="inlineLabel">Alert on complete</label>
  104. </form>
  105. </section>
  106. <section id="easingSection">
  107. <form>
  108. <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
  109. <div class="inlineLeft marginLeft">
  110. <select id="easingFnsDropdown" class="marginRight">
  111. <option value="easeOutExpo" selected>easeOutExpo (default, built-in)</option>
  112. <option value="outQuintic">outQuintic</option>
  113. <option value="outCubic">outCubic</option>
  114. </select>
  115. <input type="button" value="Apply easing" onClick="createCountUp()">
  116. </div>
  117. </form>
  118. </section>
  119. <section class="marginBottom">
  120. <div class="col full marginBottom marginTop">
  121. <div class="code-contain marginBottom">
  122. <code id="codeVisualizer" class="indigo">var options = {<br>
  123. &emsp;&emsp;useEasing : true, <br>
  124. &emsp;&emsp;easingFn : null, <br>
  125. &emsp;&emsp;useGrouping : true, <br>
  126. &emsp;&emsp;separator : ',', <br>
  127. &emsp;&emsp;decimal : '.' <br>
  128. }<br>
  129. var demo = new CountUp("myTargetElement", 24.02, 94.62, 0, 2, options);<br>
  130. demo.start();
  131. </code>
  132. </div>
  133. </div>
  134. </section>
  135. </div>
  136. </body>
  137. <script type="text/javascript">
  138. // set CountUp options
  139. // you don't need to do this - you can use the default options
  140. var demo, code, data, stars, easingFunctions,
  141. useOnComplete = false,
  142. useEasing = true,
  143. easingFn = null,
  144. useGrouping = true,
  145. options = {
  146. useEasing : useEasing, // toggle easing
  147. easingFn : easingFn, // defaults to easeOutExpo, but you can specify your own
  148. useGrouping : useGrouping, // 1,000,000 vs 1000000
  149. separator : ',', // character to use as a separator
  150. decimal : '.', // character to use as a decimal
  151. };
  152. window.onload = function() {
  153. // in case we're testing angular
  154. if (typeof angular !== 'undefined') return;
  155. // setup CountUp object
  156. demo = new CountUp('myTargetElement', 0, 94.62, 2, 2.5, options);
  157. // you could do demo.start() right here but we are getting actual current star count from github api below
  158. // since it is an asynchronous call, we fire start() in the success fn of the XMLHttpRequest object
  159. getStars.send();
  160. // display version (no hassling with markup!)
  161. document.getElementById('version').innerHTML = 'v'+demo.version();
  162. };
  163. easingFunctions = {
  164. easeOutExpo: function(t, b, c, d) {
  165. return c * (-Math.pow(2, -10 * t / d) + 1) * 1024 / 1023 + b;
  166. },
  167. outQuintic: function(t, b, c, d) {
  168. var ts = (t /= d) * t;
  169. var tc = ts * t;
  170. return b + c * (tc * ts + -5 * ts * ts + 10 * tc + -10 * ts + 5 * t);
  171. },
  172. outCubic: function(t, b, c, d) {
  173. var ts = (t /= d) * t;
  174. var tc = ts * t;
  175. return b + c * (tc + -3 * ts + 3 * t);
  176. }
  177. };
  178. // for demo:
  179. function swapValues() {
  180. var oldStartVal = document.getElementById("startVal").value;
  181. var oldEndVal = document.getElementById("endVal").value;
  182. document.getElementById("startVal").value = oldEndVal;
  183. document.getElementById("endVal").value = oldStartVal;
  184. updateCodeVisualizer();
  185. }
  186. function getEasingFn() {
  187. var fn = document.getElementById("easingFnsDropdown").value;
  188. if (fn === 'easeOutExpo') return null;
  189. if (typeof easingFunctions[fn] === 'undefined') return undefined;
  190. return easingFunctions[fn];
  191. }
  192. function getEasingFnBody(fn) {
  193. fn = typeof fn === 'undefined' ? getEasingFn() : fn;
  194. if (typeof fn === 'undefined') return 'undefined function';
  195. if (fn !== null) {
  196. return fn.toString().replace(/^ {8}/gm, '');
  197. }
  198. return '';
  199. }
  200. function createCountUp() {
  201. var startVal = document.getElementById("startVal").value;
  202. startVal = Number(startVal.replace(',','').replace(' ',''));
  203. var endVal = document.getElementById("endVal").value;
  204. endVal = Number(endVal.replace(',','').replace(' ',''));
  205. var decimals = document.getElementById("decimals").value,
  206. duration = document.getElementById("duration").value,
  207. prefix = document.getElementById("prefix").value,
  208. suffix = document.getElementById("suffix").value,
  209. easingFn = getEasingFn();
  210. options = {
  211. useEasing : useEasing,
  212. easingFn : typeof easingFn === 'undefined' ? null : easingFn,
  213. useGrouping : useGrouping,
  214. separator : document.getElementById("separator").value,
  215. decimal : document.getElementById("decimal").value,
  216. prefix: prefix,
  217. suffix: suffix
  218. };
  219. // you don't have to create a new instance of CountUp every time you start an animation,
  220. // you can just change the properties individually. But I do here in case user changes values in demo.
  221. demo = new CountUp("myTargetElement", startVal, endVal, decimals, duration, options);
  222. if (useOnComplete) {
  223. demo.start(methodToCallOnComplete);
  224. } else {
  225. demo.start();
  226. }
  227. updateCodeVisualizer();
  228. }
  229. function showCodeAndPauseResume() {
  230. code = 'demo.pauseResume();';
  231. document.getElementById("codeVisualizer").innerHTML = code;
  232. demo.pauseResume();
  233. }
  234. function showCodeAndReset() {
  235. code = 'demo.reset();';
  236. document.getElementById("codeVisualizer").innerHTML = code;
  237. demo.reset();
  238. }
  239. function showCodeAndUpdate() {
  240. var updateVal = document.getElementById("updateVal").value;
  241. var num = updateVal ? updateVal : 0;
  242. demo.update(num);
  243. }
  244. function toggleOnComplete(checkbox) {
  245. if (checkbox.checked) {
  246. useOnComplete = true;
  247. } else {
  248. useOnComplete = false;
  249. }
  250. updateCodeVisualizer();
  251. }
  252. function toggleEasing(checkbox) {
  253. var easingSection = document.getElementById("easingSection");
  254. if (checkbox.checked) {
  255. useEasing = true;
  256. easingSection.style.display = "";
  257. document.getElementById("easingFnsDropdown").value = "easeOutExpo";
  258. document.getElementById("easingFnPreview").value = "";
  259. } else {
  260. useEasing = false;
  261. easingSection.style.display = "none";
  262. }
  263. updateCodeVisualizer();
  264. }
  265. function toggleGrouping(checkbox) {
  266. if (checkbox.checked) {
  267. useGrouping = true;
  268. } else {
  269. useGrouping = false;
  270. }
  271. updateCodeVisualizer();
  272. }
  273. function methodToCallOnComplete() {
  274. console.log('COMPLETE!');
  275. alert('COMPLETE!');
  276. }
  277. function updateCodeVisualizer() {
  278. var startVal = document.getElementById("startVal").value;
  279. startVal = Number(startVal.replace(',','').replace(' ',''));
  280. var endVal = document.getElementById("endVal").value;
  281. endVal = Number(endVal.replace(',','').replace(' ',''));
  282. var decimals = document.getElementById("decimals").value;
  283. var duration = document.getElementById("duration").value;
  284. var separator = document.getElementById("separator").value;
  285. var decimal = document.getElementById("decimal").value;
  286. var prefix = document.getElementById("prefix").value;
  287. var suffix = document.getElementById("suffix").value;
  288. var easingFn = getEasingFn();
  289. var easingFnBody = getEasingFnBody(easingFn);
  290. var code = '';
  291. if (useEasing && easingFn) {
  292. code += 'var easingFn = ';
  293. var split = easingFnBody.split('\n');
  294. for (var line in split) {
  295. code += split[line].replace(' ', '&nbsp;') + '<br>';
  296. }
  297. }
  298. code += 'var options = {<br>';
  299. code += (useEasing) ? '&emsp;&emsp;useEasing : true, <br>' : '&emsp;&emsp;useEasing : false, <br>';
  300. code += (easingFn && useEasing) ? '&emsp;&emsp;easingFn: easingFn, <br>' : '';
  301. code += (useGrouping) ? '&emsp;&emsp;useGrouping : true, <br>' : '&emsp;&emsp;useGrouping : false, <br>';
  302. code += '&emsp;&emsp;separator : \''+separator+'\', <br>';
  303. code += '&emsp;&emsp;decimal : \''+decimal+'\', <br>';
  304. code += '&emsp;&emsp;prefix : \''+prefix+'\', <br>';
  305. code += '&emsp;&emsp;suffix : \''+suffix+'\' <br>';
  306. code += '};<br>';
  307. code += 'var demo = new CountUp("myTargetElement", '+startVal+', '+endVal+', '+decimals+', '+duration+', options);<br>';
  308. if (useOnComplete) {
  309. code += 'demo.start(methodToCallOnComplete);';
  310. } else {
  311. code += 'demo.start();';
  312. }
  313. document.getElementById("codeVisualizer").innerHTML = code;
  314. }
  315. function updateCodeVisualizerForUpdate() {
  316. var updateVal = document.getElementById("updateVal").value;
  317. var num = updateVal ? updateVal : 0;
  318. code = 'demo.update(' + updateVal + ');';
  319. document.getElementById("codeVisualizer").innerHTML = code;
  320. }
  321. // get current star count
  322. var repoInfoUrl = 'https://api.github.com/repos/inorganik/CountUp.js';
  323. var getStars = new XMLHttpRequest();
  324. getStars.open('GET', repoInfoUrl, true);
  325. getStars.timeout = 5000;
  326. getStars.onreadystatechange = function() {
  327. // 2: received headers, 3: loading, 4: done
  328. if (getStars.readyState == 4) {
  329. if (getStars.status == 200) {
  330. if (getStars.responseText !== 'undefined') {
  331. if (getStars.responseText.length > 0) {
  332. data = JSON.parse(getStars.responseText);
  333. stars = data.stargazers_count;
  334. // change input values
  335. document.getElementById("startVal").value = 0;
  336. document.getElementById("endVal").value = stars;
  337. document.getElementById("decimals").value = 0;
  338. createCountUp();
  339. }
  340. }
  341. }
  342. }
  343. };
  344. getStars.onerror = function() {
  345. console.error('error getting stars:', getStars.status);
  346. stars = getStars.status;
  347. demo.start();
  348. };
  349. </script>
  350. </html>