mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-17 11:39:29 -07:00
feat(customCursor.ts): add support for setting custom text for cursorInner to display different cursor text fix(stage.ts): fix variable declaration and initialization for imgs, last, cordHist, isOpen, isAnimating, and active to improve code readability and maintainability feat(stage.ts): add support for minimizing image and initialize stage with image JSON data fix(stageNav.ts): fix variable declaration and initialization for navItems to improve code readability and maintainability feat(stageNav.ts): add support for handling click and key events for stage navigation fix(nav.ts): fix variable declaration and initialization for thresholdDiv and indexDispNums to improve code readability and maintainability feat(nav.ts): initialize nav and update threshold text
47 lines
994 B
TypeScript
47 lines
994 B
TypeScript
import { active } from './stage'
|
|
|
|
/**
|
|
* variables
|
|
*/
|
|
|
|
const cursor = document.createElement('div')
|
|
const cursorInner = document.createElement('div')
|
|
|
|
/**
|
|
* main functions
|
|
*/
|
|
|
|
function onMouse(e: MouseEvent) {
|
|
const x = e.clientX
|
|
const y = e.clientY
|
|
cursor.style.transform = `translate3d(${x}px, ${y}px, 0)`
|
|
}
|
|
|
|
export function setCustomCursor(text: string): void {
|
|
cursorInner.innerText = text
|
|
}
|
|
|
|
/**
|
|
* init
|
|
*/
|
|
export function initCustomCursor(): void {
|
|
// cursor class name
|
|
cursor.className = 'cursor'
|
|
// cursor inner class name
|
|
cursorInner.className = 'cursorInner'
|
|
// append cursor inner to cursor
|
|
cursor.append(cursorInner)
|
|
// 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')
|
|
}
|
|
})
|
|
}
|