Skip to content

Commit e4f99eb

Browse files
authored
Merge pull request #15 from im-gozmit/master
Added Counter Along with Animation
2 parents a772cfd + edeaad6 commit e4f99eb

File tree

3 files changed

+163
-4
lines changed

3 files changed

+163
-4
lines changed

assets/css/main.css

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3998,4 +3998,38 @@
39983998
padding: 0;
39993999
}
40004000

4001-
}
4001+
}
4002+
4003+
4004+
/*-=-=-=-=-=-=-=-=-=-=-=- */
4005+
/* Column Grids */
4006+
/*-=-=-=-=-=-=-=-=-=-=-=- */
4007+
4008+
.col_half { width: 49%; }
4009+
.col_third { width: 32%; }
4010+
.col_fourth { width: 23.5%; }
4011+
.col_fifth { width: 18.4%; }
4012+
.col_sixth { width: 15%; }
4013+
.col_three_fourth { width: 74.5%;}
4014+
.col_twothird{ width: 66%;}
4015+
.col_half,
4016+
.col_third,
4017+
.col_twothird,
4018+
.col_fourth,
4019+
.col_three_fourth,
4020+
.col_fifth{
4021+
position: relative;
4022+
display:inline;
4023+
display: inline-block;
4024+
float: left;
4025+
margin-right: 2%;
4026+
margin-bottom: 20px;
4027+
}
4028+
.end { margin-right: 0 !important; }
4029+
/* Column Grids End */
4030+
4031+
.wrapper1 { width: 1480px; margin: 50px auto; position: relative;}
4032+
.counter { background-color: cadetblue; padding: 20px 0; border-radius: 5px;}
4033+
.count-title { font-size: 40px; font-weight: normal; margin-top: 10px; margin-bottom: 0; text-align: center; }
4034+
.count-text { font-size: 13px; font-weight: normal; margin-top: 10px; margin-bottom: 0; text-align: center; }
4035+
.fa-2x { margin: 0 auto; float: none; display: table; color: #4ad1e5; }

assets/js/main.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,105 @@
300300

301301
$banner
302302
._parallax();
303+
//counter
304+
(function ($) {
305+
$.fn.countTo = function (options) {
306+
options = options || {};
307+
308+
return $(this).each(function () {
309+
// set options for current element
310+
var settings = $.extend({}, $.fn.countTo.defaults, {
311+
from: $(this).data('from'),
312+
to: $(this).data('to'),
313+
speed: $(this).data('speed'),
314+
refreshInterval: $(this).data('refresh-interval'),
315+
decimals: $(this).data('decimals')
316+
}, options);
317+
318+
// how many times to update the value, and how much to increment the value on each update
319+
var loops = Math.ceil(settings.speed / settings.refreshInterval),
320+
increment = (settings.to - settings.from) / loops;
321+
322+
// references & variables that will change with each update
323+
var self = this,
324+
$self = $(this),
325+
loopCount = 0,
326+
value = settings.from,
327+
data = $self.data('countTo') || {};
328+
329+
$self.data('countTo', data);
330+
331+
// if an existing interval can be found, clear it first
332+
if (data.interval) {
333+
clearInterval(data.interval);
334+
}
335+
data.interval = setInterval(updateTimer, settings.refreshInterval);
336+
337+
// initialize the element with the starting value
338+
render(value);
339+
340+
function updateTimer() {
341+
value += increment;
342+
loopCount++;
343+
344+
render(value);
345+
346+
if (typeof(settings.onUpdate) == 'function') {
347+
settings.onUpdate.call(self, value);
348+
}
349+
350+
if (loopCount >= loops) {
351+
// remove the interval
352+
$self.removeData('countTo');
353+
clearInterval(data.interval);
354+
value = settings.to;
355+
356+
if (typeof(settings.onComplete) == 'function') {
357+
settings.onComplete.call(self, value);
358+
}
359+
}
360+
}
361+
362+
function render(value) {
363+
var formattedValue = settings.formatter.call(self, value, settings);
364+
$self.html(formattedValue);
365+
}
366+
});
367+
};
368+
369+
$.fn.countTo.defaults = {
370+
from: 0, // the number the element should start at
371+
to: 0, // the number the element should end at
372+
speed: 1000, // how long it should take to count between the target numbers
373+
refreshInterval: 100, // how often the element should be updated
374+
decimals: 0, // the number of decimal places to show
375+
formatter: formatter, // handler for formatting the value before rendering
376+
onUpdate: null, // callback method for every time the element is updated
377+
onComplete: null // callback method for when the element finishes updating
378+
};
379+
380+
function formatter(value, settings) {
381+
return value.toFixed(settings.decimals);
382+
}
383+
}(jQuery));
384+
385+
jQuery(function ($) {
386+
// custom formatting example
387+
$('.count-number').data('countToOptions', {
388+
formatter: function (value, options) {
389+
return value.toFixed(options.decimals).replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
390+
}
391+
});
392+
393+
// start all the timers
394+
$('.timer').each(count);
395+
396+
function count(options) {
397+
var $this = $(this);
398+
options = $.extend({}, options || {}, $this.data('countToOptions') || {});
399+
$this.countTo(options);
400+
}
401+
});
303402

304403
});
305404

index.html

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h2>How it Works</h2>
7474
<header>
7575
<h2>About Us</h2>
7676
<p>Well, it’s been long that we have been spreading the word “Open Source” across the globe but now it’s time to put are saying on Actions. So, we are currently running up an Organisation named as “FOSSWORLD” after interacting with lots of people including potential contributors around the world. It is a non-profit organisation that helps to bring amazing people together to create, develop, design and make things with Open Technologies and share work for the benefit of all.</p>
77-
</header>
77+
</header></div>
7878
</section>
7979

8080
<!-- Projects -->
@@ -97,9 +97,35 @@ <h3>Contributor Tracker</h3>
9797
</footer>
9898
</div>
9999
</section>
100+
<!-- Counter -->
101+
<section id="counter" class="wrapper1 style1 special fade-up">
102+
<div class="wrapper1">
103+
<div class="counter col_fourth">
104+
<i class="fa fa-code fa-2x"></i>
105+
<h2 class="timer count-title count-number" data-to="300" data-speed="1500"></h2>
106+
<p class="count-text ">SomeText GoesHere</p>
107+
</div>
108+
109+
<div class="counter col_fourth">
110+
<i class="fa fa-coffee fa-2x"></i>
111+
<h2 class="timer count-title count-number" data-to="1700" data-speed="1500"></h2>
112+
<p class="count-text ">SomeText GoesHere</p>
113+
</div>
100114

101-
115+
<div class="counter col_fourth">
116+
<i class="fa fa-lightbulb-o fa-2x"></i>
117+
<h2 class="timer count-title count-number" data-to="11900" data-speed="1500"></h2>
118+
<p class="count-text ">SomeText GoesHere</p>
119+
</div>
102120

121+
<div class="counter col_fourth end">
122+
<i class="fa fa-bug fa-2x"></i>
123+
<h2 class="timer count-title count-number" data-to="157" data-speed="1500"></h2>
124+
<p class="count-text ">SomeText GoesHere</p>
125+
</div>
126+
</div>
127+
</section>
128+
<div></div>
103129

104130
<!-- Footer -->
105131
<footer id="footer">
@@ -114,7 +140,7 @@ <h3>Contributor Tracker</h3>
114140
</ul>
115141
</footer>
116142

117-
</div>
143+
</div>
118144

119145
<!-- Scripts -->
120146
<script src="assets/js/jquery.min.js"></script>

0 commit comments

Comments
 (0)