-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
110 lines (91 loc) · 2.51 KB
/
index.ts
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
import { LitElement, html } from "lit";
import { property, customElement, state } from "lit/decorators.js";
export const tagName = "scroll-to-top-wc";
@customElement("scroll-to-top-wc")
export class ScrollToTop extends LitElement {
@property()
activatewhen: number = 200;
@state()
showToast: Boolean = false;
@property({ type: Boolean }) fancy: Boolean = false;
render() {
return html`
<style>
:host {
position: fixed;
bottom: 20px;
display: block;
}
.showToast {
opacity: 0.9;
//transition: 1s all ease-in-out;
}
.hideToast {
visibility: hidden;
transform: rotateY(90deg);
//transition: 1s all ease-in-out;
opacity: 0;
}
.fancy {
transition: 1s all ease-in-out;
}
.FlipContainer {
perspective: 800px;
}
.card {
transform-style: preserve-3d;
}
.showToast,
.hideToast {
background-color: var(--scroll-top-background-color, white);
color: var(--scroll-top-color, black);
cursor: pointer;
padding: 1rem;
border-radius: 1rem;
border: 1px solid black;
}
</style>
<div class="FlipContainer">
<div class="card">
<div
part="container"
class="${this.showToast ? "showToast " : "hideToast "} +
${this.fancy ? " fancy" : " "} "
@click="${this.topFunction}"
>
<slot name="text">Top</slot>
</div>
</div>
</div>
`;
}
firstUpdated() {
// When the user scrolls down XXpx from the top of the document, show the button
window.onscroll = this.scrollFunction.bind(this);
}
scrollFunction() {
if (
document.body.scrollTop > this.activatewhen ||
document.documentElement.scrollTop > this.activatewhen
) {
// console.log("time to show the toast!");
this.showToast = true;
} else {
// console.log("not showing the toast ");
this.showToast = false;
}
}
//When the user clicks on the button, scroll to the top of the document
topFunction() {
//console.log("scroll-to-top-wc: initiating scroll");
let event = new CustomEvent("scrolling", {
detail: {
message: "activated scroll to top",
},
bubbles: true,
composed: true,
});
this.dispatchEvent(event);
window.scrollTo({ top: 0, behavior: "smooth" });
}
}