41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
// modules/wheel-boost/index.js
|
|
import { registerFrameTask, unregisterFrameTask } from '../../core/frameloop.js';
|
|
|
|
/*
|
|
let velocity = 0;
|
|
let taskId = 'wheel-boost';
|
|
let damping = 0.85;
|
|
let boost = 1.2;
|
|
let enabled = true;
|
|
|
|
export function init(config = {}) {
|
|
damping = typeof config.damping === 'number' ? config.damping : 0.85;
|
|
boost = typeof config.boost === 'number' ? config.boost : 1.2;
|
|
enabled = config.enabled !== false;
|
|
|
|
if (!enabled) return;
|
|
|
|
window.addEventListener('wheel', onWheel, { passive: false });
|
|
|
|
registerFrameTask(taskId, () => {
|
|
if (Math.abs(velocity) > 0.1) {
|
|
window.scrollBy(0, velocity);
|
|
velocity *= damping;
|
|
} else {
|
|
velocity = 0;
|
|
}
|
|
}, { autoStart: true });
|
|
}
|
|
|
|
function onWheel(e) {
|
|
velocity += e.deltaY * boost;
|
|
e.preventDefault(); // verhindert das native Scrollen
|
|
}
|
|
|
|
export function destroy() {
|
|
window.removeEventListener('wheel', onWheel);
|
|
unregisterFrameTask(taskId);
|
|
velocity = 0;
|
|
}
|
|
*/
|