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 |Name | 70 |Type | 71 |Default | 72 |Description | 73 |
---|---|---|---|
start | 78 |integer | 79 |0 |
80 | Start value for span. | 81 |
incrementer|decrementer.bold | 84 |boolean | 85 |true | 86 |Whether the incrementer|decrementer is bold | 87 |
incrementer|decrementer.color | 90 |CSS color string | 91 |null | 92 |Change the incrementer|decrementer's text color | 93 |
incrementer|decrementer.class | 96 |string | 97 |null | 98 |Add a class to the incrementer|decrementer element | 99 |
showThousands | 102 |boolean | 103 |false |
104 | Whether to use a thousands separate everywhere. | 105 |
thousandSep | 108 |strings | 109 |, |
110 | The thousand separator to use. | 111 |
116 | 117 |
Methods | 121 |Param | 122 |
---|---|
'increment' |
127 | integer by which to increment | 128 |
'decrement' |
131 | absolute value of integer by which to decrement (always positive) | 132 |
'reset' |
135 | 136 | |
'get' |
139 | 140 | |
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 |151 | - 152 | - 153 | 154 |
155 |$('#basic_1').levelup('increment', 1);157 | 171 | 172 |
Increment by bigger value
173 |The increment and decrement methods allow for other values.
174 |176 | - 177 | - 178 | 179 |
180 |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 |203 | - 204 | - 205 | 206 |
207 |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 |233 | - 234 | 235 |
236 |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 |257 | - 258 | 259 |
260 |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 |290 | - 291 | 292 |
293 |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 |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 |338 | - 339 | - 340 | : 341 | 342 |
343 |$('#basic_8').levelup('get');345 | 360 | 361 |