mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
refactor(stageNav.ts): rename getIsAnimating to isAnimating.get for better readability and consistency refactor(stageNav.ts): rename addActiveCallback to active.addWatcher for better readability and consistency feat(stageNav.ts): add check for isOpen.get() and isAnimating.get() before handling key events to prevent unwanted actions
39 lines
962 B
TypeScript
39 lines
962 B
TypeScript
import { active } from './stage'
|
|
|
|
let cursor: HTMLDivElement
|
|
|
|
// create cursor
|
|
cursor = document.createElement('div')
|
|
cursor.className = 'cursor'
|
|
cursor.classList.add('active')
|
|
// create cursor inner
|
|
const cursorInner = document.createElement('div')
|
|
cursorInner.className = 'cursorInner'
|
|
// append cursor inner to cursor
|
|
cursor.append(cursorInner)
|
|
|
|
function onMouse(e: MouseEvent) {
|
|
const x = e.clientX
|
|
const y = e.clientY
|
|
cursor.style.transform = `translate3d(${x}px, ${y}px, 0)`
|
|
}
|
|
|
|
export function initCustomCursor(): void {
|
|
// append cursor to main
|
|
document.getElementById('main')!.append(cursor)
|
|
// bind mousemove event to window
|
|
window.addEventListener('mousemove', onMouse)
|
|
// add active callback
|
|
active.addWatcher(() => {
|
|
if (active.get()) {
|
|
cursor.classList.add('active')
|
|
} else {
|
|
cursor.classList.remove('active')
|
|
}
|
|
})
|
|
}
|
|
|
|
export function setCustomCursor(text: string): void {
|
|
cursorInner.innerText = text
|
|
}
|