38 |

The Basics

39 |

This jQuery plugin provides a basic +1/-1 animation to a number styled similar to how scores were updated in old video games.

40 | 41 |

Installation

42 |

Basically just include the file. 43 |

 44 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 45 | <script src="/libs/jquery-levelup/jquery.levelup.min.js"></script>
 46 | 
 47 | <span>counter <span style="font-weight: bold;" id='the_cnt'>0</span></span>
 48 | 
 49 | <script>
 50 |     var $tc = $('#the_cnt');
 51 |     $tc.levelup({'start' : 0});
 52 | 
 53 |     $('#incrementBtn').on('click', function(event) {
 54 |         $tc.levelup('increment', 1);
 55 |         $(this).blur();
 56 |     });
 57 |     $('#decrementBtn').on('click', function(event) {
 58 |         $tc.levelup('decrement', 1);
 59 |         $(this).blur();
 60 |     });
 61 | </script>
 62 | 
63 | 64 |

Usage

65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
NameTypeDefaultDescription
startinteger0Start value for span.
incrementer|decrementer.boldbooleantrueWhether the incrementer|decrementer is bold
incrementer|decrementer.colorCSS color stringnullChange the incrementer|decrementer's text color
incrementer|decrementer.classstringnullAdd a class to the incrementer|decrementer element
showThousandsbooleanfalseWhether to use a thousands separate everywhere.
thousandSepstrings,The thousand separator to use.
114 |
115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 |
MethodsParam
'increment'integer by which to increment
'decrement'absolute value of integer by which to decrement (always positive)
'reset'
'get'
143 | 144 |

Demos

145 |

I will put a few demos here.

146 |

Basic Demo

147 |

It was originally written as just a small JavaScript animation and this version 148 | is effectively what I started with before adding features.

149 |
150 |

151 | - 152 | - 153 | 154 |

155 |
156 |
$('#basic_1').levelup('increment', 1);
157 | 171 | 172 |

Increment by bigger value

173 |

The increment and decrement methods allow for other values.

174 |
175 |

176 | - 177 | - 178 | 179 |

180 |
181 |
182 | $('#basic_2').levelup('increment', 10);
183 | $('#basic_2').levelup('decrement', 7);
184 | 198 | 199 |

Non-bold option

200 |

The incrementer and decrementer are bold by default, but you can turn that off

201 |
202 |

203 | - 204 | - 205 | 206 |

207 |
208 |
209 | $('#basic_3').levelup({'start' : 0, 'incrementer' : {'bold' : false}});
210 | $('#basic_3').levelup('increment', 10);
211 | $('#basic_3').levelup('decrement', 7);
212 | 227 | 228 |

Controlling the color

229 |

You can specify the text color. This can be done via a class as well, but 230 | this is for those who simply wish to control one aspect of it.

231 |
232 |

233 | - 234 | 235 |

236 |
237 |
238 | $('#basic_4').levelup({'start' : 0, 'incrementer' : {'color' : 'red'}});
239 | $('#basic_4').levelup('increment', 10);
240 | 
241 | 252 | 253 |

Controlling the class

254 |

You can style the incrementer/decrementer however you like via a class.

255 |
256 |

257 | - 258 | 259 |

260 |
261 |
262 | <style>
263 |     .fun_times {
264 |       background-color: lightblue;
265 |       color: #FFA500;
266 |       box-shadow: 0 0 10px 10px #fff;
267 |     }
268 | </style>
269 |       
270 |
271 | $('#basic_5').levelup({'start' : 0, 'incrementer' : {'class' : 'fun_times'}});
272 | $('#basic_5').levelup('increment', 10);
273 | 
274 | 285 | 286 |

Controlling the thousands separator

287 |

You can set the thousands separator as anything you want. It is off by default.

288 |
289 |

290 | - 291 | 292 |

293 |
294 |
295 | $('#basic_6').levelup({'start' : 1111, 'showThousands' : true});
296 | $('#basic_6').levelup('increment', 5555);
297 | 
298 | 308 | 309 |

Accumulator is not span - still must be inline display type

310 |

If you don't use a span, which is inlined, you'll need to manually inline the type. This is 311 | a temporary fix that relates to where it lines up the animation.

312 |
313 |
314 |

315 | 316 |
317 |
318 |
319 | $('#basic_7').levelup({'start' : 1111, 'showThousands' : true});
320 | $('#basic_7').levelup('increment', 5555);
321 | 
322 | 332 | 333 |

Value Accessor

334 |

You'll want to use this to get the value instead of reading the text, 335 | because the text could be out of date.

336 |
337 |

338 | - 339 | - 340 | : 341 | 342 |

343 |
344 |
$('#basic_8').levelup('get');
345 | 360 | 361 |

License

362 |

Apache License 2.0

363 | 364 |
365 | 366 | 367 | Follow @pstrinkle 368 | 369 | 370 |
371 |