Commit 29e83bd3 authored by akiraohgaki's avatar akiraohgaki

Merge branch 'develop'

parents 71cfa071 8e51d539
Pipeline #359 passed with stage
in 2 minutes and 2 seconds
const {ipcRenderer} = require('electron'); const {ipcRenderer} = require('electron');
function applySmoothScroll() { function applySmoothScroll() {
let timeoutId = null; let requestId = null;
let frame = 0;
const frameMax = 50;
let amount = 0;
const amountMax = 7;
let deltaX = 0; let deltaX = 0;
let deltaY = 0; let deltaY = 0;
const amount = 2; let scrollLeft = 0;
let scrollTop = 0;
document.scrollingElement.addEventListener('wheel', (event) => { const easeOut = (p) => {
event.preventDefault(); return p * (2 - p);
};
deltaX += event.deltaX * amount; const scroll = () => {
deltaY += event.deltaY * amount; frame++;
document.scrollingElement.scrollTo({
left: scrollLeft + (deltaX * easeOut(frame / frameMax)),
top: scrollTop + (deltaY * easeOut(frame / frameMax))
});
if (frame === frameMax) {
frame = 0;
amount = 0;
cancelAnimationFrame(requestId);
}
else {
requestId = requestAnimationFrame(scroll);
}
};
if (timeoutId === null) { document.scrollingElement.addEventListener('wheel', (event) => {
timeoutId = setTimeout(() => { event.preventDefault();
document.scrollingElement.scrollBy({ if (Math.sign(deltaX) !== Math.sign(event.deltaX)
left: deltaX, || Math.sign(deltaY) !== Math.sign(event.deltaY)
top: deltaY, ) {
behavior: 'smooth' amount = 0;
}); }
timeoutId = null; if (amount < amountMax) {
deltaX = 0; amount++;
deltaY = 0; }
}, 150); deltaX = event.deltaX * amount;
deltaY = event.deltaY * amount;
scrollLeft = document.scrollingElement.scrollLeft;
scrollTop = document.scrollingElement.scrollTop;
if (frame) {
frame = 0;
cancelAnimationFrame(requestId);
} }
scroll();
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment