Skip to content

Commit 3eb530d

Browse files
Fix countup on community page (#40904)
Co-authored-by: Copilot <[email protected]>
1 parent 4464f94 commit 3eb530d

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

sass/homeassistant/pages/community/_stats.scss

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,19 @@
1-
@property --num {
2-
syntax: '<integer>';
3-
initial-value: 0;
4-
inherits: false;
5-
}
6-
71
.stats {
8-
92
display: flex;
103
flex-wrap: wrap;
114
gap: 24px 40px;
125

13-
&[data-dsap-seen] {
14-
.stat {
15-
.stat-value span {
16-
--num: attr(data-value type(#{'<number>'}));
17-
}
18-
}
19-
}
20-
216
.stat {
227
display: flex;
238
flex-direction: column;
249
min-width: 100px;
2510

26-
@for $i from 0 through 10 {
27-
&:nth-child(#{$i + 1}) {
28-
.stat-value span {
29-
transition-delay: #{$i * 0.15}s;
30-
}
31-
}
32-
}
33-
3411
.stat-value {
3512
@include h3;
3613

3714
color: var(--color-secondary);
3815
display: flex;
3916
gap: 4px;
40-
41-
span {
42-
--num: 0;
43-
44-
transition: --num 1.5s ease-out;
45-
counter-reset: num var(--num);
46-
47-
&::after {
48-
content: counter(num);
49-
}
50-
}
5117
}
5218

5319
.stat-label {

source/community/components/_global.html

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,45 @@ <h2>A Global Community, Growing Every Day</h2>
3535
<div class="photos-wrapper">
3636
<div class="photos" data-dsap>
3737
<figure class="photo large">
38-
<img src="/images/community/utrecht.webp" alt="A crowd of people gathering in a bar - Utrecht, Netherlands" />
38+
<img src="/images/community/utrecht.webp"
39+
alt="A crowd of people gathering in a bar - Utrecht, Netherlands" />
3940
<figcaption>Community Day 2025 - Utrecht</figcaption>
4041
</figure>
4142
<figure class="photo medium">
42-
<img src="/images/community/berlin.webp" alt="A group of 6 people standing in front of a bar - Berlin, Germany" />
43+
<img src="/images/community/berlin.webp"
44+
alt="A group of 6 people standing in front of a bar - Berlin, Germany" />
4345
<figcaption>Community Meetup - IFA Berlin 2025</figcaption>
4446
</figure>
4547
<figure class="photo small">
46-
<img src="/images/community/columbus.webp" alt="A few people gathering around a table demonstrating ESP32 hardware - Columbus, Ohio" />
48+
<img src="/images/community/columbus.webp"
49+
alt="A few people gathering around a table demonstrating ESP32 hardware - Columbus, Ohio" />
4750
<figcaption>Community Day 2025 - Columbus</figcaption>
4851
</figure>
4952
</div>
5053
</div>
5154
</div>
52-
</section>
55+
</section>
56+
<script>
57+
document.addEventListener("DOMContentLoaded", function () {
58+
const observer = new IntersectionObserver((entries) => {
59+
entries.forEach((entry) => {
60+
if (entry.isIntersecting) {
61+
const stats = document.querySelectorAll("#global .stat-value span[data-value]");
62+
stats.forEach((stat) => {
63+
let demo = new countUp.CountUp(stat, stat.getAttribute("data-value"));
64+
if (!demo.error) {
65+
demo.start();
66+
} else {
67+
console.error(demo.error);
68+
}
69+
});
70+
observer.unobserve(entry.target);
71+
}
72+
});
73+
}, { threshold: 0.1 });
74+
const statsElement = document.querySelector("#global .stats");
75+
if (statsElement) {
76+
observer.observe(statsElement);
77+
}
78+
});
79+
</script>

source/community/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
og_image: /images/community/og.jpeg
66
frontpage: false
77
---
8+
<script src="https://cdn.jsdelivr.net/gh/inorganik/[email protected]/dist/countUp.umd.js" type="module"></script>
89
<link rel="stylesheet" href="/stylesheets/homeassistant/pages/community/index.css" />
910
<script type="module">
1011
import {DSAP} from "/javascripts/dsap.es.js";

0 commit comments

Comments
 (0)