-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDemo2.tsx
105 lines (98 loc) · 3.32 KB
/
Demo2.tsx
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
import React, { useRef } from "react";
import Center from "../components/Center/Center";
// import ScrollSpy from "../components/src";
import ScrollSpy from "react-ui-scrollspy";
interface Props {}
const Demo2 = (props: Props) => {
const parentScrollContainerRef = useRef<HTMLDivElement | null>(null);
const onPress = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
e.preventDefault();
const target = window.document.getElementById(
e.currentTarget.href.split("#")[1]
);
if (target) {
var headerOffset = 20;
var elementPosition = target.getBoundingClientRect().top;
var offsetPosition = elementPosition - headerOffset;
window.scrollBy({
top: offsetPosition,
behavior: "smooth",
});
}
};
return (
<>
<div className="container-fluid">
<div className="row">
<div
className="col-md-4 col-sm-4 col-lg-4"
style={{ backgroundColor: "green" }}
>
<div className="position-relative w-100">
<div
className="position-fixed top-0 ps-5 text-white"
style={{ marginTop: "calc(60vh/2)" }}
>
<h1 className="mb-5">Example Heading</h1>
<a onClick={(e) => onPress(e)} href={"#section-1"}>
<div
style={{ textAlign: "center" }}
data-to-scrollspy-id="section-1"
className="ss-item-demo-2"
>
Section 1
</div>
</a>
<a onClick={(e) => onPress(e)} href={"#section-2"}>
<div
data-to-scrollspy-id="section-2"
className="ss-item-demo-2 text-center"
>
Section 2
</div>
</a>
<a onClick={(e) => onPress(e)} href={"#section-3"}>
<div
data-to-scrollspy-id="section-3"
className="ss-item-demo-2 text-center"
>
Section 3
</div>
</a>
</div>
</div>
</div>
<div className="col-md-8 col-sm-8 col-lg-8 flex-column d-flex justify-content-center p-0">
<div
ref={parentScrollContainerRef}
// style={{
// position: "relative",
// overflowY: "scroll",
// height: "50vh",
// }}
>
<ScrollSpy
// parentScrollContainerRef={parentScrollContainerRef}
activeClass="ss-active-demo-2"
offsetBottom={100}
scrollThrottle={80}
useBoxMethod
>
<Center id="section-1" backgroundColor="orange" height="150vh">
<p>Section 1</p>
</Center>
<Center id="section-2" backgroundColor="brown" height="150vh">
<p>Section 2</p>
</Center>
<Center id="section-3" backgroundColor="blue" height="150vh">
<p>Section 3</p>
</Center>
</ScrollSpy>
</div>
</div>
</div>
</div>
</>
);
};
export default Demo2;