-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
91 lines (74 loc) · 2.63 KB
/
main.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
const JSON_DATA = {
"big_title" : "Tree Planting Robot Soil Panel",
"button1": {
"text": "Mr. X should test his garden soil using the NPK sensor and adjust the nutrient levels if needed before planting the mango trees. Applying the recommended fertilizers and incorporating organic matter like compost can help achieve these ideal values.",
"name": "Mango",
"soil": 60,
"nit": 40,
"pho": 70,
"pot": 36
},
"button2": {
"text": "Mr. X should test his garden soil using the NPK sensor and adjust the nutrient levels if needed before planting the apple trees. Applying the recommended fertilizers and incorporating organic matter like compost can help achieve these ideal values.",
"name": "Apple",
"soil": 40,
"nit": 20,
"pho": 90,
"pot": 46
},
"button3": {
"text": "Mr. X should test his garden soil using the NPK sensor and adjust the nutrient levels if needed before planting the orage trees. Applying the recommended fertilizers and incorporating organic matter like compost can help achieve these ideal values.",
"name": "Orange",
"soil": 70,
"nit": 29,
"pho": 65,
"pot": 89
}
}
window.addEventListener("DOMContentLoaded", () => {
// start the animation when the element is in the page view
const elements = [].slice.call(document.querySelectorAll(".pie"));
const circle = new CircularProgressBar("pie");
// circle.initial();
if ("IntersectionObserver" in window) {
const config = {
root: null,
rootMargin: "0px",
threshold: 0.75,
};
const ovserver = new IntersectionObserver((entries, observer) => {
entries.map((entry) => {
if (entry.isIntersecting && entry.intersectionRatio > 0.75) {
circle.initial(entry.target);
observer.unobserve(entry.target);
}
});
}, config);
elements.map((item) => {
ovserver.observe(item);
});
} else {
elements.map((element) => {
circle.initial(element);
});
}
$(document).ready(function () {
let jsonData = JSON_DATA;
// OnClick Pie Update
$(".dot").on("click", function (e) {
let btn = $(this).data("attr");
$('.ideal-tree').text(jsonData[btn].name);
$('.test-text').text(jsonData[btn].text);
$('.big-title').text(jsonData.big_title);
// update circle when range change
const pie = document.querySelectorAll(".pie");
pie.forEach((el, index) => {
const options = {
index: index + 1,
percent: jsonData[btn][$(el).data('type')],
};
circle.animationTo(options);
});
});
});
});