Skip to content

Commit 1eefd49

Browse files
committed
Version 2.1
Changes! Now the counter start when you scroll until it.
1 parent 8672e6e commit 1eefd49

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

countup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: WP CountUP JS
44
Plugin URI: https://inorganik.github.io/countUp.js/
55
Description: You can create a lot of animated numerical counters and display it into your site.
6-
Version: 1.1
6+
Version: 2.1
77
Author: Roel Magdaleno
88
Author URI: https://twitter.com/roelmagdaleno
99
License: GPLv2

js/show_counter.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
jQuery(document).ready(function($){
2+
var eventFired = false;
23
var options = {};
34

45
//Loop to class counter which contains all data provided into the shortcode.
5-
$.each($('.counter'), function(){
6+
$.each($('.counter'), function(index, value){
7+
$(this).attr('id', 'counter-' + index); //Add an id to each counter.
8+
69
var start = $(this).data('start');
710
var count = $(this).data('count');
811
var decimals = $(this).data('decimals');
@@ -33,9 +36,21 @@ jQuery(document).ready(function($){
3336
}
3437
});
3538

36-
var numAnim = new CountUp(this, start, count, decimals, duration, options);
39+
//Get counter id.
40+
var counterId = $(this).attr('id');
3741

38-
numAnim.start();
39-
});
42+
//Object Instance.
43+
var numAnim = new CountUp(counterId, start, count, decimals, duration, options);
44+
45+
//Scroll function to execute the animation number when it scrolled to the object.
46+
var objectPositionTop = $('#' + counterId).offset().top - window.innerHeight;
47+
48+
$(window).on('scroll', function(){
49+
var currentPosition = $(document).scrollTop();
4050

51+
if(currentPosition > objectPositionTop && eventFired === false){
52+
numAnim.start();
53+
}
54+
});
55+
});
4156
});

readme.txt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: Roel Magdaleno
33
Tags: wordpress, plugin, counter, countup, countupjs, animated
44
Requires at least: 3.5
5-
Tested up to: 4.4.2
6-
Stable tag: "trunk"
5+
Tested up to: 4.5.2
6+
Stable tag: 2.1
77
License: GPLv2
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -27,7 +27,23 @@ Use this plugin, is very easy, you can use it quickly after install it. To do th
2727

2828
[countup start="your-value" end="your-value" decimals="your-value" duration="your-value"]
2929

30-
The shortcode accepts four arguments, as you can see previously:
30+
** VERSION 2.0 **
31+
32+
Also you can add the options from CountUP.js Options Page inside of the shortcode, like this:
33+
34+
[countup easing="true" groupig="false" separator="," decimal="." prefix="this_prefix" suffix="this_suffix"]
35+
36+
If you don't use these options inside of the shortcode, the default values will be pull from CountUp.js Options Page.
37+
38+
** END VERSION 2.0 **
39+
40+
** VERSION 2.1 **
41+
42+
All counters started their animation before to reach the target counter. Now, when you scrolled to the target counter, the counter will start their animation.
43+
44+
** END VERSION 2.1 **
45+
46+
The shortcode accepts those arguments, as you can see previously:
3147

3248
[countup
3349
start="your-value" //This use a number to begin the counter.
@@ -36,7 +52,7 @@ The shortcode accepts four arguments, as you can see previously:
3652
duration="your-value" //This use a number (seconds) as duration of the counter.
3753
]
3854

39-
Example: [countup start="0" end="55" decimals="0" duration="5"]
55+
Example: [countup start="0" end="55" decimals="0" duration="5" prefix="my_prefix"]
4056

4157
Now you know how to use this plugin, but you can edit some options if you required (Go to "Settings"->"CountUP.js").
4258

@@ -52,10 +68,21 @@ Now you know how to use this plugin, but you can edit some options if you requir
5268
1. Screenshot-1: Output counters on the site.
5369
2. Screenshot-2: Shortcode example.
5470
3. Screenshot-3: Plugin options page.
71+
4. Screenshot-4: CountUp.js Options inside shortcode.
72+
5. Screenshot-5: Output counters on the site with individual prefix and suffix.
5573

5674
== Changelog ==
5775

5876
= 1.0 =
5977
* Release
6078

79+
= 1.1 =
80+
* jQuery issue was solved.
81+
82+
= 2.0 =
83+
* Now you can add the options from CountUP.js Options Page inside of the shortcode. Please check Usage and Options for more information.
84+
85+
= 2.1 =
86+
* All counters started their animation before to reach the target counter. Now, when you scrolled to the target counter, the counter will start their animation.
87+
6188
== Upgrade Notice ==

screenshot-4.png

27.1 KB
Loading

screenshot-5.png

96 KB
Loading

0 commit comments

Comments
 (0)