-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
166 lines (157 loc) · 4.97 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
$(document).on("click", 'a[href^="#"]', function (event) {
event.preventDefault();
$("html, body").animate(
{
scrollTop: $($.attr(this, "href")).offset().top,
},
700
);
});
var piesiteFired = 0;
$(document).ready(function () {
var $win = $(window),
$win_height = $(window).height(),
// - A multiple of viewport height - The higher this number the sooner triggered.
windowPercentage = $(window).height() * 0.9;
$win.on("scroll", scrollReveal);
function scrollReveal() {
var scrolled = $win.scrollTop();
///////////////////////////////////////
// Bar Charts scroll activate, looking for .trigger class to fire.
$(".trigger").each(function () {
var $this = $(this),
offsetTop = $this.offset().top;
if (scrolled + windowPercentage > offsetTop || $win_height > offsetTop) {
$(this).each(function (key, bar) {
var percentage = $(this).data("percentage");
$(this).css("height", percentage + "%");
///////////////////////////////////////
// Animated numbers
$(this)
.prop("Counter", 0)
.animate(
{
Counter: $(this).data("percentage"),
},
{
duration: 2000,
easing: "swing",
step: function (now) {
$(this).text(Math.ceil(now));
},
}
);
// Animated numbers
///////////////////////////////////////
});
} else {
///////////////////////////////////////
// To keep them triggered, lose this block.
$(this).each(function (key, bar) {
$(this).css("height", 0);
});
}
});
///////////////////////////////////////
// Horizontal Chart
$(".chartBarsHorizontal .bar").each(function () {
var $this = $(this),
offsetTop = $this.offset().top;
if (scrolled + windowPercentage > offsetTop || $win_height > offsetTop) {
$(this).each(function (key, bar) {
var percentage = $(this).data("percentage");
$(this).css("width", 2.5 * percentage + "%");
///////////////////////////////////////
// Animated numbers
$(this)
.prop("Counter", 0)
.animate(
{
Counter: $(this).data("percentage"),
},
{
duration: 2000,
easing: "swing",
step: function (now) {
$(this).text(Math.ceil(now));
},
}
);
// Animated numbers
///////////////////////////////////////
});
} else {
///////////////////////////////////////
// To keep them triggered, lose this block.
$(this).each(function (key, bar) {
$(this).css("width", 0);
});
}
});
///////////////////////////////////////
// Radial Graphs - scroll activate
$(".piesite").each(function () {
var $this = $(this),
offsetTop = $this.offset().top;
if (scrolled + windowPercentage > offsetTop || $win_height > offsetTop) {
if (piesiteFired == 0) {
timerSeconds = 3;
timerFinish = new Date().getTime() + timerSeconds * 1000;
$(".piesite").each(function (a) {
pie = $("#pie_" + a).data("pie");
timer = setInterval("stoppie(" + a + ", " + pie + ")", 0);
});
piesiteFired = 1;
}
} else {
// To keep them triggered, lose this block.
$(".piesite").each(function () {
piesiteFired = 0;
});
}
});
}
scrollReveal();
});
///////////////////////////////////////
// The Radial Graphs
///////////////////////////////////////
// The following code is originally from the excellent pen:
// https://codepen.io/StephenScaff/pen/VYaQGB by Stephen Scaff
var timer;
var timerFinish;
var timerSeconds;
function drawTimer(c, a) {
$("#pie_" + c).html(
'<div class="percent"></div><div id="slice"' +
(a > 50 ? ' class="gt50"' : "") +
'><div class="pie"></div>' +
(a > 50 ? '<div class="pie fill"></div>' : "") +
"</div>"
);
var b = (360 / 100) * a;
$("#pie_" + c + " #slice .pie").css({
"-moz-transform": "rotate(" + b + "deg)",
"-webkit-transform": "rotate(" + b + "deg)",
"-o-transform": "rotate(" + b + "deg)",
transform: "rotate(" + b + "deg)",
});
a = Math.floor(a * 100) / 100;
arr = a.toString().split(".");
intPart = arr[0];
$("#pie_" + c + " .percent").html(
'<span class="int">' + intPart + "</span>" + "%"
);
}
function stoppie(d, b) {
var c = (timerFinish - new Date().getTime()) / 1000;
var a = 100 - (c / timerSeconds) * 100;
a = Math.floor(a * 100) / 100;
if (a <= b) {
drawTimer(d, a);
} else {
b = $("#pie_" + d).data("pie");
arr = b.toString().split(".");
$("#pie_" + d + " .percent .int").html(arr[0]);
}
}