-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a09042
commit a708d37
Showing
7 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
liscom-scroll-to-top { | ||
opacity: 0; | ||
position: fixed; | ||
bottom: 2rem; | ||
right: 2rem; | ||
z-index: 99; | ||
border: none; | ||
outline: none; | ||
background-color: rgba(0, 0, 0, 0.1); | ||
box-shadow: rgba(0,0,0,0.2) 0px 0px 5px; | ||
color: white; | ||
cursor: pointer; | ||
padding: 10px; | ||
border-radius: 4px; | ||
|
||
display: flex; | ||
align-content: center; | ||
align-items: center; | ||
text-align: center; | ||
|
||
justify-content: center; | ||
width: 2.8rem; | ||
height: 2.8rem; | ||
transition: opacity 0.5s ease-in-out, background-color 0.2s ease-in-out; | ||
&:hover { | ||
background-color: rgba(0, 0, 0, 0.2); | ||
} | ||
&.show { | ||
opacity: 1; | ||
} | ||
* { | ||
color: white; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {customElement} from "@kasimirjs/embed"; | ||
|
||
|
||
@customElement("liscom-scroll-to-top") | ||
class ScrollToTop extends HTMLElement { | ||
|
||
|
||
|
||
connectedCallback() { | ||
console.log("scroll to top"); | ||
this.addEventListener("click", () => { | ||
window.scrollTo({top: 0, behavior: "smooth"}); | ||
}); | ||
let active = false; | ||
|
||
if (this.innerHTML.trim() === "") | ||
this.innerHTML = "⬆️"; | ||
|
||
window.addEventListener("scroll", () => { | ||
if (window.scrollY > 300 && active === false) { | ||
this.classList.add("show"); | ||
active = true; | ||
} | ||
if (window.scrollY < 300 && active === true) { | ||
this.classList.remove("show"); | ||
active = false; | ||
} | ||
}, {passive: true}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {ka_create_element, ka_debounce} from "@kasimirjs/embed"; | ||
import {customElement} from "@kasimirjs/embed"; | ||
import {ka_dom_ready} from "@kasimirjs/embed"; | ||
|
||
|
||
@customElement("liscom-scrollspy") | ||
export class LiscomScrollspy extends HTMLElement { | ||
|
||
private elements = {} as {[key: string]: {target: HTMLElement, nav: HTMLElement, observer: IntersectionObserver}}; | ||
|
||
public async connectedCallback() { | ||
await ka_dom_ready(); | ||
// Allow attaching to any element | ||
this.style.display = "contents"; | ||
|
||
|
||
|
||
document.querySelectorAll("[data-scrollspy-name]").forEach((el : HTMLElement) => { | ||
let curName = el.getAttribute("data-scrollspy-name"); | ||
let navElem = ka_create_element("li", {class: ""}, | ||
[ | ||
ka_create_element("a", {href: window.location.pathname + "#" + el.getAttribute("id")}, curName) | ||
], | ||
this | ||
); | ||
|
||
|
||
let curMo = new IntersectionObserver((entries) => { | ||
if (entries[0].isIntersecting) { | ||
navElem.classList.add("active"); | ||
} else { | ||
navElem.classList.remove("active"); | ||
} | ||
}); | ||
curMo.observe(el); | ||
this.elements[curName] = ({target: el, nav: navElem, observer: curMo}); | ||
}) | ||
|
||
} | ||
|
||
async disconnectedCallback() { | ||
// disconnect all observers | ||
for(let key in this.elements) { | ||
this.elements[key].observer.disconnect(); | ||
this.elements[key].nav.remove(); | ||
} | ||
|
||
} | ||
|
||
// language=html | ||
|
||
} |