mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-17 11:39:29 -07:00
fix(customCursor.ts): add return type void to onMouse function for clarity fix(customCursor.ts): add passive option to window event listener for mousemove to improve performance fix(stageNav.ts): move import statement for setCustomCursor to the top for better organization fix(stageNav.ts): add return type void to handleClick function for clarity fix(stageNav.ts): add return type void to handleKey function for clarity fix(stageNav.ts): add passive option to overlay event listeners for click, keydown, mouseover, and focus to improve performance fix(stageNav.ts): add passive option to window event listener for keydown to improve performance fix(stageNav.ts): add return type void to nextImage function for clarity fix(stageNav.ts): add return type void to prevImage function for clarity fix(gallery.ts): move import statement for Swiper to the top for better organization fix(gallery.ts): add return type void to slideUp function for clarity fix(gallery.ts): add return type void to initGallery function for clarity fix(gallery.ts): add passive option to window event listener for touchstart to improve performance fix(gallery.ts): add return type void to changeSlide function for clarity fix(gallery.ts): add return type void to scrollToActive function for clarity fix(gallery.ts): add return type void to createGallery function for clarity fix(gallery.ts): add passive option to close event listeners for click and keydown to improve performance fix(gallery.ts): add passive option to overlay event listeners for click, keydown, mouseover, and focus to improve performance fix(gallery.ts): add passive option to window event listener for touchstart to improve performance fix(nav.ts): add return type void to initNav function for clarity fix(utils.ts): add return type number to getRandom function for clarity fix(utils.ts): add return type void to onVisible function for clarity fix(utils.ts): add return type void to addWatcher function in Watchable class for clarity
49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import { container } from '../container'
|
|
|
|
import { active } from './stage'
|
|
|
|
/**
|
|
* variables
|
|
*/
|
|
|
|
const cursor = document.createElement('div')
|
|
const cursorInner = document.createElement('div')
|
|
|
|
/**
|
|
* main functions
|
|
*/
|
|
|
|
function onMouse(e: MouseEvent): void {
|
|
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
|
|
container.append(cursor)
|
|
// bind mousemove event to window
|
|
window.addEventListener('mousemove', onMouse, { passive: true })
|
|
// add active callback
|
|
active.addWatcher(() => {
|
|
if (active.get()) {
|
|
cursor.classList.add('active')
|
|
} else {
|
|
cursor.classList.remove('active')
|
|
}
|
|
})
|
|
}
|