Skip to content

Commit f3a6779

Browse files
Merge pull request #485 from HackRU/badge_update
badge update
2 parents 001d382 + bcb94f7 commit f3a6779

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/MLHBadge.jsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,61 @@
11
import React, { Component } from "react";
22

33
class MLHBadge extends Component {
4+
constructor(props) {
5+
super(props);
6+
this.handleScroll = this.handleScroll.bind(this);
7+
this.handleResize = this.handleResize.bind(this);
8+
this.state = {
9+
isVisible: true,
10+
badgeHeight: 0,
11+
};
12+
}
13+
14+
handleResize() {
15+
let badge = document.getElementById("mlh-trust-badge");
16+
if (badge == null) {
17+
return;
18+
}
19+
this.setState({
20+
badgeHeight: parseFloat(
21+
window
22+
.getComputedStyle(badge)
23+
.getPropertyValue("height")
24+
.replace("px", "")
25+
),
26+
});
27+
}
28+
29+
handleScroll() {
30+
let badgeHeight = this.state.badgeHeight;
31+
let offset = window.pageYOffset;
32+
if (offset < badgeHeight) {
33+
//At top
34+
this.setState({
35+
isVisible: true,
36+
});
37+
} else if (offset > badgeHeight) {
38+
this.setState({
39+
isVisible: false,
40+
});
41+
}
42+
}
43+
44+
componentDidMount() {
45+
window.addEventListener("scroll", this.handleScroll);
46+
window.addEventListener("resize", this.handleResize);
47+
this.handleResize();
48+
}
49+
50+
componentWillUnmount() {
51+
window.removeEventListener("scroll", this.handleScroll);
52+
window.removeEventListener("resize", this.handleResize);
53+
}
54+
455
render() {
556
return (
57+
this.state.isVisible
58+
&&
659
<a id="mlh-trust-badge"
760
style={{display:"block",maxWidth:"100px",minWidth:"60px",position:"fixed",right:"50px",top:0,width:"10%", zIndex:10000}}
861
href="https://mlh.io/seasons/2022/events?utm_source=na-hackathon&utm_medium=TrustBadge&utm_campaign=2022-season&utm_content=white">

0 commit comments

Comments
 (0)